Skip to content

Should use fully qualified names in error messages #4154

@marienz

Description

@marienz

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions