Skip to content

Dict key autocomplete not working when importing the dictionnary #4771

Answered by erictraut
ClementJ18 asked this question in Q&A
Discussion options

You must be logged in to vote

I think this is working as intended. The completion provider (the component that presents completion suggestions) bases its suggestions on type information. With an untyped dict such as the_dict in the first example, the inferred type is simply dict[str, int]. That type doesn't contain any information about the keys in the dict. And since it's a mutable type, the keys could be changed dynamically.

IIRC, there was some special-case logic added to pylance's completion provider for locally-assigned dict expressions that allow it to offer key name suggestions from the dict expression within the module. This explains why this works locally but doesn't work across module boundaries.

Defining a …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@erictraut
Comment options

Answer selected by ClementJ18
@ClementJ18
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants