This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make rlcompleter avoid duplicate global names
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: martin.panter, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-11-19 02:14 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
global-dupes.patch martin.panter, 2015-11-19 02:14 review
Messages (5)
msg254873 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-19 02:14
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
msg254882 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-19 07:57
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.
msg255238 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-24 00:40
New changeset 4799615f4f26 by Martin Panter in branch '3.4':
Issue #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 #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 #25663: Merge rlcompleter fix from 3.5
https://hg.python.org/cpython/rev/96fb9daf64a5

New changeset f742c31491e3 by Martin Panter in branch 'default':
Issue #25663: Update rlcompleter test for new 3.6 behaviour
https://hg.python.org/cpython/rev/f742c31491e3
msg255239 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-24 01:19
New changeset d3a9b055206c by Martin Panter in branch '2.7':
Issue #25663: Make rlcompleter avoid duplicate global names
https://hg.python.org/cpython/rev/d3a9b055206c
msg255243 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-24 02:07
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.
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69849
2016-05-13 12:39:24martin.panterunlinkissue22143 superseder
2016-05-13 12:28:37martin.panterlinkissue22143 superseder
2015-11-24 02:07:50martin.pantersetstatus: open -> closed
resolution: fixed
messages: + msg255243

stage: patch review -> resolved
2015-11-24 01:19:07python-devsetmessages: + msg255239
2015-11-24 00:40:33python-devsetnosy: + python-dev
messages: + msg255238
2015-11-19 07:57:07serhiy.storchakasetmessages: + msg254882
2015-11-19 07:20:43serhiy.storchakasetnosy: + serhiy.storchaka
2015-11-19 02:14:21martin.pantercreate