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
Consider the following code, which contains a type error. We expect a Type[MyProtocol], but we pass in a Type[SomeClass] instead, where SomeClass is incompatible with MyProtocol:
...results in the same nice error message, as expected.
(I would just go ahead and fix this myself, but I'm busy with other things atm, so filing this here so I don't forget about it/in case somebody else has some spare time.)
The text was updated successfully, but these errors were encountered:
Michael0x2a
changed the title
Error messages when Type[X] is not a subtype of Type[SomeProtocol] are not very descriptive
Error messages when Type[X] is not a subtype of Type[SomeProtocol] are not very descriptive
Jul 25, 2018
I think it was just overlooked (as maybe some other cases). Also note that after fixing #4536 there will be two more cases like this: a protocol vs. Type[...], and a protocol vs. CallableType with is_type_obj() returning True.
error: Argument 1 to "test" has incompatible type "List[SomeClass]"; expected "List[MyProtocol]"
Specifying this:
test([SomeClass()])
does give the desired, more informative, output:
error: List item 0 has incompatible type "SomeClass"; expected "MyProtocol"
note: Following member(s) of "SomeClass" have conflicts:
note: Expected:
note: def foo(self) -> int
note: Got:
note: def foo(self) -> str
This is a bit different, and it looks like it will be hard to give a better error message in this case, because we would need to track the "source" of incompatibility for generic classes.
Consider the following code, which contains a type error. We expect a
Type[MyProtocol]
, but we pass in aType[SomeClass]
instead, whereSomeClass
is incompatible withMyProtocol
:The error message we get is just
Argument 1 to "test" has incompatible type "Type[SomeClass]"; expected "Type[MyProtocol]"
.It would be nice if we got the more detailed error message we usually get when misusing protocols instead. For example, if we modify the code to:
...we get:
I think this is probably just an oversight having specifically to do with
Type
-- doing stuff like:...results in the same nice error message, as expected.
(I would just go ahead and fix this myself, but I'm busy with other things atm, so filing this here so I don't forget about it/in case somebody else has some spare time.)
The text was updated successfully, but these errors were encountered: