Give better error message if type inference fails because of unsatisfiable upper bound
Open
Nobody has claimed this yet.
priority-1-normal
topic-type-variables
topic-usability
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
After #5699 in certain cases (see testWideOuterContextEmptyError) if type inference fails, mypy gives an obscure error like
Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "List[str]")
This error message could be improved. Here are some ideas:
- Record that we didn't use the outer context because of unsatisfied bound and add a note about this
- (Probably better) If type variable with a bound is used in an invariant context and we can't infer a value, we currently infer
C[<nothing>]. What if we'd instead inferredC[<bound>]?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the testWideOuterContextEmptyError case mentioned in the issue and inspect the type-inference path for an unsatisfied upper bound in an invariant context. Compare the proposed diagnostic approaches, then add a regression test showing the improved error message and run the relevant test suite.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100