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

Add autocompletion for keys in dictionaries #54560

Open
ValeryKhamenya mannequin opened this issue Nov 8, 2010 · 7 comments
Open

Add autocompletion for keys in dictionaries #54560

ValeryKhamenya mannequin opened this issue Nov 8, 2010 · 7 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ValeryKhamenya
Copy link
Mannequin

ValeryKhamenya mannequin commented Nov 8, 2010

BPO 10351
Nosy @birkenfeld, @facundobatista, @ezio-melotti, @merwok, @Trundle, @vadmium, @serhiy-storchaka
Files
  • rlcompleter-dict-keys-autocompletion.tar.gz: patch, rlcomeplter.py -- full, test_rlcompleter -- full
  • patch.diff
  • 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 = None
    created_at = <Date 2010-11-08.09:22:36.044>
    labels = ['type-feature', 'library']
    title = 'Add autocompletion for keys in dictionaries'
    updated_at = <Date 2015-12-07.10:05:22.342>
    user = 'https://bugs.python.org/ValeryKhamenya'

    bugs.python.org fields:

    activity = <Date 2015-12-07.10:05:22.342>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2010-11-08.09:22:36.044>
    creator = 'Valery.Khamenya'
    dependencies = []
    files = ['19540', '19555']
    hgrepos = []
    issue_num = 10351
    keywords = ['patch']
    message_count = 7.0
    messages = ['120721', '120753', '120855', '121451', '121631', '122125', '256042']
    nosy_count = 9.0
    nosy_names = ['georg.brandl', 'facundobatista', 'rbp', 'ezio.melotti', 'eric.araujo', 'Trundle', 'Valery.Khamenya', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue10351'
    versions = ['Python 3.6']

    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Nov 8, 2010

    1. The patch introduces autocompletion for keys in dictionaries (patch attached)

    2. The patched rlcompleter as such works OK for unicode dictionary keys as well. All tests pass OK. HOWEVER, readline's completion mechanism seem to be confused with unicode strings -- see comments to Completer.dict_key_matches(). So, perhaps, one day some changes should be applied to readline code too.

    3. rlcompleter.py has no tests in trunk -- I spawn a separate issue for it. Meanwhile I took test_rlcompleter.py from 2.7 and extended it.

    4. The following usual lines in .pythonstartup:
      import readline
      import rlcompleter
      readline.parse_and_bind('tab: complete')
      readline.parse_and_bind('Control-Space: complete')

    should be extended by this one:
    readline.set_completer_delims(re.compile(r'[\'"\\[]').sub('', readline.get_completer_delims()))

    @ValeryKhamenya ValeryKhamenya mannequin added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Nov 8, 2010
    @merwok
    Copy link
    Member

    merwok commented Nov 8, 2010

    Thank you for the report and patch. This is a new feature, thus targetting the py3k branch (future 3.2). If your patch is not against this branch, can you refresh it? Also, please attach it as text file(s), and generally follow guidelines outlined at http://www.python.org/dev/patches/ Thanks again!

    @merwok merwok changed the title to introduce autocompletion for keys in dictionaries (patch attached) Add autocompletion for keys in dictionaries Nov 8, 2010
    @merwok merwok added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Nov 8, 2010
    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Nov 9, 2010

    Hi Éric, thanks for guiding.

    So, attached is the concatenation of two forward unified diffs for rlcompleter.py and test_rlcompleter.py -- both as of py3k trunk. Tested against Python 3.1.2 though.

    P.S. hm, py3k code appeared to be surprisingly nicer -- no unicode troubles and work-arounds at all...

    regards
    Valery

    @ValeryKhamenya ValeryKhamenya mannequin added the docs Documentation in the Doc dir label Nov 9, 2010
    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Nov 18, 2010

    Guys, do you expect anythig else from me in respect to this issue? Let me know it before my non-stopable garbage collector wipes all the details from my brain away :)

    @merwok
    Copy link
    Member

    merwok commented Nov 20, 2010

    I will review your patch later today.

    @merwok
    Copy link
    Member

    merwok commented Nov 22, 2010

    Review time!

    + elif "[" in text:
    + self.matches = self.dict_key_matches(text)
    Does this complete only dicts? What about other mappings? What about other sequences implementing __getitem__? One of the function name and the function docstring (“Compute matches when text contains a [”) is wrong.

    I’m not familiar with rlcompleter’s internals, so I’d like a few comments sprinkled in the code.

    Please wrap your lines at 79 columns, and follow other advice given at http://www.python.org/dev/patches/ for the next version of your patch.

    + The evaluation of the part before the '[' could be enhanced.
    This belongs in a comment or a test, not the docstring.

    + 'DictCompleteMe[\'öh, вау!\']',
    I find it more readable to avoid escaped quotes whenever possible. Here I would use "DictCompleteMe['öh, вау!']".

    @merwok merwok removed the docs Documentation in the Doc dir label Nov 22, 2010
    @vadmium
    Copy link
    Member

    vadmium commented Dec 7, 2015

    Some thoughts and observations from trying this patch out:

    • It supports single and double quotes, but triple-quoted strings get trashed
    • It supports Python 2’s u". . ." syntax, but not r". . .", b". . .", etc
    • It supports integer keys, but not indexes of lists
    • It does not seem to support multi-level dictionaries (e.g. config parser): d[key1][key2]
    • Control codes in strings are awkward
    • Escape codes in strings don’t seem to be parsed or generated properly
    • The module doc string would sort of become out of date: “indexing operations are *not* evaluated”

    It works for custom dictionaries, so it can invoke custom code to list the keys. Maybe this is okay; I wouldn’t expect listing an object’s keys to have a serious effect. But you could add a Mapping (and Sequence) ABC check in case the object implements keys() but is not really a dictionary.

    It would be nice for this to work by default, because Tab completion is now enabled by default. But I worry if changing the default completer delimiters globally will be a compatibility problem.

    There is a mega ugly regular expression in the patch. Is there another way to do whatever it is doing? Failing that, you could add comments, group names, etc to make it more understandable.

    @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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants