Skip to content

Union types for dict keys are not inferred in union context #6079

Open
@bryanforbes

Description

@bryanforbes

mypy: 0.650
Python: 3.7.1

I'm not sure if this is a bug or a new feature, however the following code is unexpected (in my mind, especially coming from TypeScript):

d = {"1": 2, 3: 4}
reveal_type(d)  # builtins.dict[builtins.object*, builtins.int*]

I would have expected mypy to infer the type of d as builtins.dict[Union[builtins.str*, builtins.int*], builtins.int*].

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions