Skip to content

Give better error messages when there are covariance/invariance related errors #1115

Closed
@JukkaL

Description

@JukkaL

[The following is adapted from discussion at #1113. Go there for more context.]

We should give output like this for some invariance violations, as many programmers expect everything to be covariant and it may not be obvious why mypy is complaining:

$ mypy file.py
file.py:7: error: Argument 1 to "f" has incompatible type Dict[str, List[int]]; expected Dict[str, Sequence[int]]
file.py:8: note: The second type parameter of "Dict" is invariant; consider using "Mapping" instead, which is covariant

This would give more context even for somebody who doesn't understand covariance/invariance -- these terms are easy to google.

Even better, we could give a pointer to relevant documentation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions