Skip to content

Union[]s as dict[] values #2300

Closed
Closed
@Herst

Description

@Herst

Mypy does not detect the subtype relation (correct term?) when it comes to dict values:

if False:
    from typing import Union

# works
foo1 = 0 # type: int
bar1 = foo1 # type: Union[int, str]

# "Incompatible types in assignment"
foo2 = {} # type: dict[str, int]
bar2 = foo2 # type: dict[str, Union[int, str]]

Mypy 0.4.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions