-
Notifications
You must be signed in to change notification settings - Fork 768
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
Show key type info when hovering over an index lookup on TypedDicts #4694
Comments
Pulled out a helper for finding the type that the string is a key for. Copied some logic for verifying that the StringNode is the only node within a StringListNode from the completion logic. There appears to be some jank in the find definition logic that doesn't verify if a StringNode is the only element in a StringListNode. https://github.com/microsoft/pyright/issues/5655 https://github.com/microsoft/pyright/issues/5654
The hover provider shows the types of identifiers in your code. It doesn't do anything for a string literal because the type of that string literal is, well, a In any case, I will transfer this request to the pylance-release project since it relates to a language server feature. The pylance team can decide whether to pursue this enhancement request or wait for additional feedback from pylance users. @rchiodo or @debonte, could you transfer this to pylance-release? Thanks! |
Moving this issue to discussion as an enhancement request for comments and upvotes. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Current Behaviour
When hovering over an index operation into a
TypedDict
variable no type info for the key appears and definition is unavailable.In contrast constructing a
TypedDict
object hovering over keys there does produce type info and definition.Expected Behaviour
Hovering over a
TypedDict
key within an indexing operation should show the key type info and the definition should be available.Motivating Use Case
Plain dictionaries often appear in legacy code bases and when migrating types into these code bases it is easier and less error prone to write
TypedDict
s to describe these dictionaries instead of migrating them into dataclasses or similar (IMO). Which do show type info when hovering over the property names.Migrating this way works well to verify that all accesses and definitions are valid. However when writing code that indexes into one of these dictionaries, finding either the type, docstring or definition of a key is cumbersome. Since the developer must find the type of the indexed object the and manually scan through to the relevant key.
Future Ideas
Hover/Definition search for
TypedDict.get
.get
is often used when keys are markedNotRequired
to skip verbose'key' in obj
checks. It may improve usability if key definitions were easily available.Hover/Definition search for
NamedTuple
indexingThe same functionality for
TypedDict
could be applied toNamedTuple
. The use case is weaker however, since the field can be directly referenced by name instead of by index.The text was updated successfully, but these errors were encountered: