Skip to content

Bound TypeVar doesn't unify with its bound #3946

@Daenyth

Description

@Daenyth
from typing import *
U = Union[int, str]
d: Dict[Type[U], int] = {int: 1, str: 2}
T = TypeVar('T', bound=U)
def get(t: Type[T]) -> int:
    return d[t]
foo.py:6: error: Invalid index type Type[T] for Dict[Union[Type[int], Type[str]], int]; expected type "Union[Type[int], Type[str]]"

Using mypy 0.521

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions