Skip to content

TypeVar bound is ignored in generic alias #10445

Closed
@JelleZijlstra

Description

@JelleZijlstra

Bug Report

A generic alias using a TypeVar with a bound allows type arguments that don't match the bound

To Reproduce

% cat tvbound.py 
import typing

FooT = typing.TypeVar("FooT", bound=str)
FooIsh = typing.Union[int, FooT]

bat2: FooIsh[float] = 1.0

% mypy tvbound.py
Success: no issues found in 1 source file
% mypy --version
mypy 0.820+dev.e8afde621531880c2b9c51acba8e565a29cde0b1

Expected Behavior

I would expect an error saying that the value of FooT cannot be float.

Found this as a result of microsoft/pyright#1839.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions