Skip to content

Incorrect error message when passing a dict to a function #1716

Closed
@SizzlingVortex

Description

@SizzlingVortex
from typing import Mapping


def func(results: Mapping[str, str]) -> None:
    pass


if __name__ == "__main__":
    # Passing an int here (even though all values should be strings) is intentional
    func({"1":"1", "2":2})

Running the above code through mypy gives me the following incorrect error message:

error: List item 1 has incompatible type "Tuple[str, int]"

Strangely enough, the next section of code (which is nearly the same as the above code) produces a better error message:

from typing import Mapping


def func(results: Mapping[str, str]) -> None:
    pass


if __name__ == "__main__":
    # Using an int here (even though all values should be strings) is intentional
    my_dict = {"1":"1", "2":2}
    func(my_dict)

Running this code through mypy gives the following (better) error message:

error: Argument 1 to "func" has incompatible type Dict[str, object]; expected Mapping[str, str]

My Specs:
Python 3.5.1
mypy-lang 0.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions