basedmypy
basedmypy copied to clipboard
Support `TypeVar`s in the bounds of other `TypeVar`s
from typing import _T as T, TypeVar
L = TypeVar("L", bound=list[T]) # error: Type variable "typing._T" is unbound
def foo(l: L) -> L | T: # error: A function returning TypeVar should receive at least one argument containing the same Typevar
res = l[0]
if res:
return res
return l
a: list[int] | list[str]
reveal_type(foo) # "def [L <: list[T?], T] (l: L) -> L | T"
reveal_type(foo(a)) # list[int] | list[str]
L = TypeVar("L", bound=list[T]) #type: ignore[valid-type]
this works but not when the bound is a TypeVar on its own
L = TypeVar("L", bound=T) #type:ignore[valid-type]
def foo(t: T, l: L) -> L:
...
a: int
reveal_type(foo(a, a)) # error
@DetachHead is that #402?