Skip to content

False positive when mixing Mapping and Union #6001

Description

@wkschwartz

A function that expects a heterogeneous dictionary and gets a dictionary with a subset of the expected types seems to cause problems.

fromtypingimportAny, Mapping, Uniondeff(arg: Mapping[ str , Any]) ->None: passdefg(arg: Mapping[Union[str, int], Any]) ->None: passf({'b': 'c'})
g({'b': 'c'})
d= {'b': 'c'}
f(d)
g(d) # <--- Line 8

Mypy's output is

mypy-test.py:8: error: Argument 1 to "g" has incompatible type "Dict[str, str]"; expected "Mapping[Union[str, int], Any]"

I'm using Python 3.7.1 and Mypy 0.641. Possibly related to #5849?

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