You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Sorry, heavily edited... it's more complex than I thought.)
AFAIU, the rule for inferring the type of lvalue in an assignment is intended to be roughly this:
Use the knowledge of lvalue type to obtain constraints on all the type variables in rvalue type.
Within those constraints, find concrete types for the type variables that result in the lowest possible final type. Replace type variables with those concrete types if not <uninhabited>.
If a concrete type found for a type variable is <uninhabited>, but the constraint is not equality, leave the type variable unsubstituted, so it becomes a type parameter in the final result
If any <uninhabited> remains, mark the code as unreachable.
I think the problem is that mypy sometimes ends up not doing step 3, instead leaving <uninhabited> in the inferred type. This leads to confusing messages and incorrect tagging of code as unreachable.
That said, I don't completely understand step 2, since the "lowest" type may not exist; but I hope the rest of my comments are still correct.
Unconstrained TypeVars should not infer UninhabitedType as the result -- it leads to confusing behavior.
(See:
testUnderspecifiedInferenceResult
)The text was updated successfully, but these errors were encountered: