-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
When mixing classes with the same name defined in different modules, it's possible to generate error messages like this that are a little difficult to decipher:
/tmp/my.py:19: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[T]], None]"; expected "Callable[[Future[T]], Any]"
/tmp/my.py:20: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Arg(Future[T], 'source')], None]"; expected "Callable[[Future[T]], None]"
The actual problem was that the "Future" on one side of the error was from a different module. It's especially difficult to spot because of the unrelated superficial differences: I assumed there was some kind of significance to one side having a named Arg while the other doesn't.
I ran into this while writing something similar to asyncio.wrap_future, which converts from one library's Future class to another's, and getting the two mixed up in my type annotations.
Including the fully qualified class names would have made the error message much more obvious.
Reactions are currently unavailable