python / python/mypy

Give better error message if type inference fails because of unsatisfiable upper bound

Open
#5,706 0 comments 0 reactions 0 assignees View on GitHub

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 inferred C[<bound>]?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.