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

Make rlcompleter avoid duplicate global names #69849

Closed
vadmium opened this issue Nov 19, 2015 · 5 comments
Closed

Make rlcompleter avoid duplicate global names #69849

vadmium opened this issue Nov 19, 2015 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Nov 19, 2015

BPO 25663
Nosy @vadmium, @serhiy-storchaka
Files
  • global-dupes.patch
  • 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 = None
    closed_at = <Date 2015-11-24.02:07:50.922>
    created_at = <Date 2015-11-19.02:14:20.907>
    labels = ['type-bug', 'library']
    title = 'Make rlcompleter avoid duplicate global names'
    updated_at = <Date 2015-11-24.02:07:50.921>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2015-11-24.02:07:50.921>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-11-24.02:07:50.922>
    closer = 'martin.panter'
    components = ['Library (Lib)']
    creation = <Date 2015-11-19.02:14:20.907>
    creator = 'martin.panter'
    dependencies = []
    files = ['41071']
    hgrepos = []
    issue_num = 25663
    keywords = ['patch']
    message_count = 5.0
    messages = ['254873', '254882', '255238', '255239', '255243']
    nosy_count = 3.0
    nosy_names = ['python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25663'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @vadmium
    Copy link
    Member Author

    vadmium commented Nov 19, 2015

    When playing with the Editline alternative to Readline, I noticed that “global” name completions can include duplicates:

    >>> No
    None                 NotADirectoryError(  NotImplementedError(
    None                 NotImplemented      
    >>> None
    None None

    It completed my line to “None”, but if you hit Tab again, it lists two duplicate options both identical to what I already have. The reason is that “None” is both a reserved keyword, and a member of the builtins module.

    My patch avoids adding extra completions if a name has already been added. It also prioritizes the global namespace over builtins, so that say if you alias “int” to a non-callable, it is no longer listed with an opening bracket “(” suffix. Earlier behaviour:

    >>> int = 81
    >>> in
    in     input( int    int(  

    Now:

    >>> in
    in     input( int

    @vadmium vadmium added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 19, 2015
    @serhiy-storchaka
    Copy link
    Member

    Nice work.

    An alternative approach is to make "matches" a dict. And instead of

        if match not in seen:
            seen.add(word)
            matches.append(match)

    use just

    matches[word] = match
    

    I don't know what approach is better.

    Added other minor comments on Rietveld.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 24, 2015

    New changeset 4799615f4f26 by Martin Panter in branch '3.4':
    Issue bpo-25663: Make rlcompleter avoid duplicate global names
    https://hg.python.org/cpython/rev/4799615f4f26

    New changeset 4ed70c568baf by Martin Panter in branch '3.5':
    Issue bpo-25663: Merge rlcompleter fix from 3.4 into 3.5
    https://hg.python.org/cpython/rev/4ed70c568baf

    New changeset 96fb9daf64a5 by Martin Panter in branch 'default':
    Issue bpo-25663: Merge rlcompleter fix from 3.5
    https://hg.python.org/cpython/rev/96fb9daf64a5

    New changeset f742c31491e3 by Martin Panter in branch 'default':
    Issue bpo-25663: Update rlcompleter test for new 3.6 behaviour
    https://hg.python.org/cpython/rev/f742c31491e3

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 24, 2015

    New changeset d3a9b055206c by Martin Panter in branch '2.7':
    Issue bpo-25663: Make rlcompleter avoid duplicate global names
    https://hg.python.org/cpython/rev/d3a9b055206c

    @vadmium
    Copy link
    Member Author

    vadmium commented Nov 24, 2015

    I chose to keep my strategy of using the set. Using a dictionary to hold the matches could mess up the order, although it looks like Readline sorts the matches before displaying them.

    @vadmium vadmium closed this as completed Nov 24, 2015
    @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

    2 participants