Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support nested dictionary key completion #1493

Closed
javad94 opened this issue Jun 24, 2021 · 8 comments
Closed

Support nested dictionary key completion #1493

javad94 opened this issue Jun 24, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@javad94
Copy link

javad94 commented Jun 24, 2021

Environment data

  • Language Server version: 2021.6.3
  • OS and version: Windows 10 20H2
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.5 using Anaconda

Expected behaviour

Pylance should show key completion for integer and nested keys.

Actual behaviour

Pylance does not show key completion for integer and nested keys.

Logs

XXX

Code Snippet / Additional information

somedict = {
    'test': 1,
    'test2':2,
    '3test':3,
    '4':4,
    5: 5,
    '_test6': 6,
    'testnested': {'n1':1, 2:2}
}

Pylance does not show key completion for integer keys (in this case 5)
image

Pylance does not show key completion for nested keys
image

@judej
Copy link
Contributor

judej commented Jun 24, 2021

Need to investigate why 5 does not show up

@judej judej added the bug Something isn't working label Jun 24, 2021
@github-actions github-actions bot removed the triage label Jun 24, 2021
@heejaechang
Copy link
Contributor

first one is a bug, but nested key is new feature request. so, probably we will fix the first one first,

@erictraut
Copy link
Contributor

Our completion provider has logic for string literals but not for other literals like integers, floats, complex, etc.

somedict = {
    5: 0,
    3.41: 0,
    3j: 0,
    [3, 4]: 0,
}

We'll need to decide where to draw the line. The vast majority of keys within dicts are strings. It drops off very quickly after that. Integers are probably next.

@javad94
Copy link
Author

javad94 commented Jun 25, 2021

@erictraut I agree with you.

@jakebailey jakebailey added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Jul 13, 2021
@cdce8p
Copy link

cdce8p commented Jul 15, 2021

Aside from strings, I usually see constants that reference strings. These seem to be unsupported at the moment, unfortunately.

Screen Shot 2021-07-15 at 12 24 35

KEY_1 = "Some key"
KEY_2 = "Some other key"

somedict = {
    KEY_1: 1,
    KEY_2: 2,
    "key_3": 3,
}

somedict[]

@yvvt0379
Copy link

@erictraut I have to explain that in your example, the last key [3, 4] is invalid because it's mutable. See the reasons https://docs.python.org/3/faq/design.html#why-must-dictionary-keys-be-immutable

@erictraut
Copy link
Contributor

Yes, good point. Replace the list with a tuple.

@jakebailey jakebailey added the needs investigation Could be an issue - needs investigation label Sep 1, 2021
@jakebailey jakebailey changed the title Dictionary key completion issue Support nested dictionary key completion Sep 2, 2021
@jakebailey jakebailey added enhancement New feature or request and removed bug Something isn't working needs investigation Could be an issue - needs investigation in backlog labels Sep 2, 2021
@judej
Copy link
Contributor

judej commented Apr 20, 2022

Moving this issue to discussion as an enhancement request for comments and upvotes.

@microsoft microsoft locked and limited conversation to collaborators Apr 20, 2022
@judej judej converted this issue into discussion #2707 Apr 20, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants