You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[2.0 regression] TypeVar with constrains Sub and Super does not accept Sub as a default value #21424
λ cat test.py
from typing import TypeVar
T = TypeVar("T", int, float)
def f(x: T = 0): ...
λ mypy test.py --no-incremental
test.py:3: error: Incompatible default for parameter "x" (default has type "int", parameter has type "T") [assignment]
Found 1 error in 1 file (checked 1 source file)
changed the title [-][2.0 regression] int float constrained typevar with int default value[/-][+][2.0 regression] TypeVar with constrains Sub and Super does not accept Sub as a default value[/+]on May 7, 2026
Activity
ilevkivskyi commentedon May 7, 2026
This is not specific to
intvsfloat, i.e. not related to promotions. The same reproduces with:[-][2.0 regression] int float constrained typevar with int default value[/-][+][2.0 regression] TypeVar with constrains Sub and Super does not accept Sub as a default value[/+]ilevkivskyi commentedon May 7, 2026
Anyway, it looks like this exposes pre-existing missing edge case in
is_subtype()and there is an easy fix. I will make a PR soon.Fix type variable with values as a supertype (#21431)