Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underspecified type variables should not infer UninhabitedType #3032

Open
ddfisher opened this issue Mar 19, 2017 · 1 comment
Open

Underspecified type variables should not infer UninhabitedType #3032

ddfisher opened this issue Mar 19, 2017 · 1 comment

Comments

@ddfisher
Copy link
Collaborator

Unconstrained TypeVars should not infer UninhabitedType as the result -- it leads to confusing behavior.

(See: testUnderspecifiedInferenceResult)

@pkch
Copy link
Contributor

pkch commented Apr 14, 2017

(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:

  1. Use the knowledge of lvalue type to obtain constraints on all the type variables in rvalue type.
  2. 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>.
  3. 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
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants