Confusing error message: List item 0 has incompatible type "Type[Linear]"; expected "Type[Linear]"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
In some situations, mypy can report that there was an incompatible type X, but then say that the expected type was also X. Regardless of whether or not the program is correct or not, this error message is bad.
To Reproduce
from typing import Any
class Linear:
def __init__(self, **kwargs) -> None:
pass
class QatLinear(Linear):
def __init__(self, qconfig=None):
pass
def f(x: Any):
if type(x) in [Linear, QatLinear]:
pass
Expected Behavior mypy gives me a good error message
Actual Behavior
(base) ezyang-mbp:~ ezyang$ mypy t.py
t.py:12: error: List item 0 has incompatible type "Type[Linear]"; expected "Type[Linear]"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: mypy 0.780
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.7
- Operating system and version: OS X
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 by running the supplied Python reproducer with the reported mypy version or a current checkout, then trace the type-checker path that formats the list-item incompatibility diagnostic. Done means the reproduced case no longer reports identical displayed types as incompatible, with regression coverage for the diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100