basedmypy
basedmypy copied to clipboard
type variables should be allowed on `ClassVar`s
class A[T]:
t: ClassVar[T]
A[int].t = 1
this is obviously an error, but:
class B(A[int]):
pass
B.t = 1
this should be allowed
also this
class A[T]:
class B[TB = T]: ...
class C(A[int]: ...
A.B() # error
A[int].B() # ok
C.B() # ok
the issue is with classmethod:
class A:
a: ClassVar[T]
@classvar
def f(cls, t: T):
cls.a = t
A[int].f(1)
A[int].f is stupid
but this is often how constructors are written:
@classmethod
def make(cls, t: T) -> Self:
return cls(t)
so the question is: how can we support both cases safely