Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bisect insort C implementation ignores methods on list subclasses #48185

Closed
jek mannequin opened this issue Sep 22, 2008 · 6 comments
Closed

bisect insort C implementation ignores methods on list subclasses #48185

jek mannequin opened this issue Sep 22, 2008 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jek
Copy link
Mannequin

jek mannequin commented Sep 22, 2008

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']

    @jek
    Copy link
    Mannequin Author

    jek mannequin commented Sep 22, 2008

    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.

    @jek jek mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 22, 2008
    @rhettinger rhettinger self-assigned this Sep 23, 2008
    @hdima
    Copy link
    Mannequin

    hdima mannequin commented Sep 26, 2008

    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.

    @amauryfa
    Copy link
    Member

    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.

    @hdima
    Copy link
    Mannequin

    hdima mannequin commented Sep 26, 2008

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

    New patch attached.

    @rhettinger
    Copy link
    Contributor

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

    @rhettinger rhettinger assigned birkenfeld and unassigned rhettinger Oct 5, 2008
    @birkenfeld
    Copy link
    Member

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants