Skip to content

bisect insort C implementation ignores methods on list subclasses #48185

Closed

Description

@jek
mannequin
BPO 3935
Nosy @birkenfeld, @rhettinger, @amauryfa
Files
  • test.py: test case
  • bisect.diff: Patch
  • bisect2.patch: Patch with PyList_CheckExact
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-10-08.18:47:48.025>
    created_at = <Date 2008-09-22.18:53:44.168>
    labels = ['type-bug', 'library']
    title = 'bisect insort C implementation ignores methods on list subclasses'
    updated_at = <Date 2008-10-08.18:47:48.023>
    user = 'https://bugs.python.org/jek'

    bugs.python.org fields:

    activity = <Date 2008-10-08.18:47:48.023>
    actor = 'georg.brandl'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-10-08.18:47:48.025>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2008-09-22.18:53:44.168>
    creator = 'jek'
    dependencies = []
    files = ['11561', '11614', '11623']
    hgrepos = []
    issue_num = 3935
    keywords = ['patch']
    message_count = 6.0
    messages = ['73589', '73867', '73873', '73881', '74348', '74543']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'rhettinger', 'hdima', 'amaury.forgeotdarc', 'jek']
    pr_nums = []
    priority = 'low'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3935'
    versions = ['Python 3.0', 'Python 2.7']

    Activity

    1. jek commented on Sep 22, 2008

      jekmannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Sep 22, 2008
    3. self-assigned this
      on Sep 23, 2008
    4. hdima commented on Sep 26, 2008

      hdimamannequin
      Mannequin

      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.

    5. amauryfa commented on Sep 26, 2008

      @amauryfa
      Contributor

      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.
    6. hdima commented on Sep 26, 2008

      hdimamannequin
      Mannequin

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

      New patch attached.

    7. rhettinger commented on Oct 5, 2008

      @rhettinger
      Contributor

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

    8. birkenfeld commented on Oct 8, 2008

      @birkenfeld
      Member

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

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions