Skip to content

Bisect upgrades: key/cmp/reverse, parameterized handedness #47624

Closed

Description

@danuznanski
BPO 3374
Nosy @rhettinger
Files
  • bisect-2.7.diff: A diff that upgrades bisect, its tests, and its documentation.
  • 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/rhettinger'
    closed_at = <Date 2008-07-16.13:00:35.275>
    created_at = <Date 2008-07-16.12:21:35.146>
    labels = ['library']
    title = 'Bisect upgrades: key/cmp/reverse, parameterized handedness'
    updated_at = <Date 2008-07-16.13:00:35.274>
    user = 'https://bugs.python.org/danuznanski'

    bugs.python.org fields:

    activity = <Date 2008-07-16.13:00:35.274>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2008-07-16.13:00:35.275>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2008-07-16.12:21:35.146>
    creator = 'dan.uznanski'
    dependencies = []
    files = ['10904']
    hgrepos = []
    issue_num = 3374
    keywords = ['patch']
    message_count = 2.0
    messages = ['69773', '69779']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'dan.uznanski']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3374'
    versions = ['Python 2.7']

    Activity

    1. danuznanski commented on Jul 16, 2008

      danuznanskimannequin
      MannequinAuthor

      Attached find a unified diff that upgrades the bisect module in two
      important ways:

      1. bisect and friends now understand cmp, key, and reverse, the same way
        that list.sort does.

      2. bisect and insort now have parameterized handedness: instead of using
        two different functions depending on whether you want new items to show
        up before or after existing ones, bisect and insort now take a flag
        called 'right' which can change the handedness on the fly.

      Currently this code fails two existing regression tests:
      test_backcompatibility, because bisect is no longer the same as
      bisect_right; and test_non_sequence, because insort now raises
      AttributeError instead of TypeError when called on an int.

      Still to do, in order of priority as perceived by me:

      1. A C version of the code needs to be written.

      2. The error handling should be worked over by somebody with more
        knowledge than I - the regression tests assume that particular failures
        (len-only, get-only, and non-sequence) will happen with one of TypeError
        or AttributeError when in reality they may raise the other.

      3. The tests for new functionality should be made more exhaustive.

      4. The in-module documentation probably needs cleaning; the rst
        documentation needs my name added to it (a good deal of the existing
        writing is still Fred L Drake's, so I won't replace) and needs to have
        the "section 3.6.4" part linked to Mutable Sequence Types; I couldn't
        find an actual example of that linkage.

      5. The godawful conditions in bisect should probably get cleaned up.

    2. added
      stdlib
      on Jul 16, 2008
    3. rhettinger commented on Jul 16, 2008

      @rhettinger
      Contributor

      Issues:

      1. In Py3.0, the cmp argument has been dropped completely. It has been
        supplanted by the key function.

      2. Previous feature requests for cmp/key/reverse have been rejected.
        The problem is that in a series of searches or insertions the key
        function should not be called more than once (as it is with sort), but
        the bisect functions potentially call it many times will the same
        argument. The granularity is wrong. Adding the cmp/key/reverse
        arguments tends to discourage correct design with a separate key table
        and a set of indexes.

      3. Guido has articulated as design principle that prefer separate
        functions to having a flag, so the separate handedness functions should
        not be combined. Also, the current design reflects typical use cases
        where an app decides on a handedness and never changes that decision.
        It would be a waste to repeated pass in a handedness argument that
        never changes.

      Marking this as rejected so that you don't lose more time writing C
      versions and whatnot.

    4. 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

    stdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions