Skip to content

Does pyright treat intermediate object types differently to objects created in a return statement? #9527

Discussion options

You must be logged in to vote

Yes, this is expected behavior. The expression within a return statement is evaluated using bidirectional type inference. The return type provides the "expected type" as context. When the same expression is assigned to a variable whose type is not declared, regular inference rules apply, since there is no context.

If you want get_param_a_1 to work the same way as get_param_a_2, you can provide an explicit type declaration for the param_a variable, as you've done in get_param_a_3.

Replies: 1 comment

Comment options

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