Thanks to visit codestin.com
Credit goes to github.com

Skip to content

False positive when mixing Mapping and Union #6001

Closed
@wkschwartz

Description

@wkschwartz

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

from typing import Any, Mapping, Union
def f(arg: Mapping[      str      , Any]) -> None: pass
def g(arg: Mapping[Union[str, int], Any]) -> None: pass
f({'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