Issue 3935: bisect insort C implementation ignores methods on list subclasses
Created on 2008-09-22 18:53 by jek, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| test.py | jek, 2008-09-22 18:53 | test case | ||
| bisect.diff | hdima, 2008-09-26 17:32 | Patch | ||
| bisect2.patch | hdima, 2008-09-26 19:48 | Patch with PyList_CheckExact | ||
| Messages (6) | |||
|---|---|---|---|
| msg73589 - (view) | Author: jason kirtland (jek) | Date: 2008-09-22 18:53 | |
The C implementation (only) of bisect does not invoke list subclass
methods when insorting. Code like this will not trigger the assert:
class Boom(list):
def insert(self, index, item):
assert False
bisect.insort(Boom(), 123)
object-derived classes are OK.
|
|||
| msg73867 - (view) | Author: Dmitry Vasiliev (hdima) | Date: 2008-09-26 17:32 | |
Actually it was an optimization. PyList_Insert() was used for list and list-derived objects. I've attached the patch which fix the issue and for me the new code looks even cleaner than the original code. |
|||
| msg73873 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2008-09-26 17:52 | |
We could keep the optimization for the standard case: What about simply replacing PyList_Check with PyList_CheckExact? - most usages use plain lists, and will even run slightly faster - list-derived objects get the desired behaviour. |
|||
| msg73881 - (view) | Author: Dmitry Vasiliev (hdima) | Date: 2008-09-26 19:48 | |
Good idea! Don't know why I didn't use it in the very first version. :-) New patch attached. |
|||
| msg74348 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2008-10-05 17:02 | |
Don't think this is too late for Py3.0. |
|||
| msg74543 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2008-10-08 18:47 | |
OK, committed as r66856, should get merged to 3.0 soon. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:39 | admin | set | github: 48185 |
| 2008-10-08 18:47:48 | georg.brandl | set | status: open -> closed messages: + msg74543 |
| 2008-10-05 17:02:41 | rhettinger | set | assignee: rhettinger -> georg.brandl versions: + Python 3.0, Python 2.7, - Python 2.6, Python 2.5 messages: + msg74348 resolution: accepted nosy: + georg.brandl |
| 2008-09-26 19:48:35 | hdima | set | files:
+ bisect2.patch messages: + msg73881 |
| 2008-09-26 17:52:35 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg73873 |
| 2008-09-26 17:32:55 | hdima | set | files:
+ bisect.diff keywords: + patch messages: + msg73867 nosy: + hdima |
| 2008-09-23 12:41:51 | rhettinger | set | priority: low assignee: rhettinger nosy: + rhettinger |
| 2008-09-22 18:53:44 | jek | create | |
