Support nested dictionary key completion #2707
Replies: 8 comments
-
Need to investigate why |
Beta Was this translation helpful? Give feedback.
-
first one is a bug, but nested key is new feature request. so, probably we will fix the first one first, |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@erictraut I agree with you. |
Beta Was this translation helpful? Give feedback.
-
Aside from strings, I usually see constants that reference strings. These seem to be unsupported at the moment, unfortunately. KEY_1 = "Some key"
KEY_2 = "Some other key"
somedict = {
KEY_1: 1,
KEY_2: 2,
"key_3": 3,
}
somedict[] |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
Yes, good point. Replace the list with a tuple. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
Environment data
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
Code Snippet / Additional information
Pylance does not show key completion for integer keys (in this case 5)

Pylance does not show key completion for nested keys

Beta Was this translation helpful? Give feedback.
All reactions