Skip to content

Weird error messages when mixing classes with instances #3050

Closed
@miedzinski

Description

@miedzinski
class A: pass
x: Tuple[A]
x = A,  # E: Incompatible types in assignment (expression has type "Tuple[A]", variable has type "Tuple[A]")
y: Tuple[Type[A]]
y = A,  # OK, expected
def f(x: Tuple[A]) -> None: return None
f((A,))  # E: Argument 1 to "f" has incompatible type "Tuple[A]"; expected "Tuple[A]"
reveal_type((A,))  # E: Revealed type is 'Tuple[def () -> x.A]'
z: A
z = A  # E: Incompatible types in assignment (expression has type "A" (type object), variable has type "A")
z = A,  # E: Incompatible types in assignment (expression has type "Tuple[A]", variable has type "A")

Looks like mypy formats class type in three ways: T (which is wrong), T (type object), and def () -> T. In some cases these errors are unclear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions