python / python/mypy

Confusing error message: List item 0 has incompatible type "Type[Linear]"; expected "Type[Linear]"

Open
#10,160 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug false-positive
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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.