Mailing List Archive

[issue3935] bisect insort C implementation ignores methods on list subclasses
New submission from jason kirtland <jek@discorporate.us>:

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.

----------
components: Library (Lib)
files: test.py
messages: 73589
nosy: jek
severity: normal
status: open
title: bisect insort C implementation ignores methods on list subclasses
type: behavior
versions: Python 2.5, Python 2.6
Added file: http://bugs.python.org/file11561/test.py

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Changes by Raymond Hettinger <rhettinger@users.sourceforge.net>:


----------
assignee: -> rhettinger
nosy: +rhettinger
priority: -> low

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Dmitry Vasiliev <dima@hlabs.spb.ru> added the comment:

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.

----------
keywords: +patch
nosy: +hdima
Added file: http://bugs.python.org/file11614/bisect.diff

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

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.

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Dmitry Vasiliev <dima@hlabs.spb.ru> added the comment:

Good idea! Don't know why I didn't use it in the very first version. :-)

New patch attached.

Added file: http://bugs.python.org/file11623/bisect2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment:

Don't think this is too late for Py3.0.

----------
assignee: rhettinger -> georg.brandl
nosy: +georg.brandl
resolution: -> accepted
versions: +Python 2.7, Python 3.0 -Python 2.5, Python 2.6

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue3935] bisect insort C implementation ignores methods on list subclasses [ In reply to ]
Georg Brandl <georg@python.org> added the comment:

OK, committed as r66856, should get merged to 3.0 soon.

----------
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue3935>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com