Skip to content

Confusing behaviour when using generic type arguments in function #8865

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

You must be logged in to vote

In the first if statement, the type of the expression {str, int, float} evaluates to type set[Unknown] with pyright's default type inference settings. This means the statement param_type in {str, int, float} does not narrow the type of param_type. For information about pyright's set expression inference rules, refer to this documentation. For more details about type narrowing and supported type guard patterns, refer to this documentation.

If you enable strictSetInference (which is enabled by default in "strict" type checking mode), the type of {str, int, float} will be inferred as set[type[str] | type[int] | type[float]], and the x in y type guard pattern should apply, allowing pyright to…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Dzeri96
Comment options

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

@Dzeri96
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
2 participants