You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Weird error messages when mixing classes with instances #3050
classA: passx: 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, expecteddeff(x: Tuple[A]) ->None: returnNonef((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: Az=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.
classA: passclassB(A): passdeff(a: A): passf(B) # E: Argument 1 to "f" has incompatible type "B"; expected "A"a: A=B# E: Incompatible types in assignment (expression has type "B", variable has type "A")
Activity
ilevkivskyi commentedon Mar 23, 2017
Yes, I remember I noticed this around a year ago, last two formats are OK I think, but the first one is definitely misleading.
ambv commentedon Apr 12, 2017
So the correct error message should be:
elazarg commentedon May 16, 2017
Example from #3372:
elazarg commentedon May 16, 2017
I will submit a PR is there is agreement on the correct error message is.
I am +1 on
Type[A]as @ambv suggested.elazarg commentedon May 16, 2017
I think the issue becomes even more confusing when dealing with metaclasses.
ilevkivskyi commentedon May 16, 2017
I am also +1 on
Type[A].gvanrossum commentedon May 16, 2017
Yup