Skip to content

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

Open
@ezyang

Description

@ezyang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions