Skip to content

Unable to infer attributes of constrained generic type parameter outside of the class #9507

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

You must be logged in to vote

Pyright is working correctly here. The Account class is generic and accepts one type argument. In the function get_balance, you have annotated the account parameter with the type Account. Since you have omitted the type argument, type checkers will assume Any (or in the case of pyright, Unknown, which is an implicit Any). That means the instance variable balance has the type Unknown.

This behavior is all prescribed by the Python typing spec, and pyright is conforming to the spec.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rdong8
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