Skip to content

How to make pyright complete a dict> #3375

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

You must be logged in to vote

The return type of get_pictures is annotated as dict. The dict class is a generic class that accepts two type arguments, but you have provided neither of them in the type annotation. When type arguments are omitted, PEP 484 indicates that type checkers should assume that they are Any. Pyright distinguishes between explicit Any and implicit Any with the latter form referred to as Unknown. So you have effectively declared that the return type of get_pictures is dict[Unknown, Unknown] — i.e. a dictionary with keys and values of any type.

In this case, you could declare the return type as dict[str, Any] or dict[str, list[Sequence[OnlineIterm] | bool | str].

If you want your dictionaries to ha…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cathaysia
Comment options

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