Closed max-muoto closed 2 months ago
Yes, this should work, so I consider this a bug. The wording of the diagnostic message is also misleading because this isn't a "type expression".
Yes, this should work, so I consider this a bug. The wording of the diagnostic message is also misleading because this isn't a "type expression".
Thanks for the quick fix!
BTW, I generally recommend using type[T]
rather than specifying an upper bound of type
for T
. This tends to work more reliably across type checkers and use cases. You can use this as a workaround while you're waiting for the bug fix.
from typing import cast
def klass_decorator[T](klass: type[T]) -> type[T]:
class Wrapped(klass):
...
return cast(type[T], Wrapped)
BTW, I generally recommend using
type[T]
rather than specifying an upper bound oftype
forT
. This tends to work more reliably across type checkers and use cases. You can use this as a workaround while you're waiting for the bug fix.from typing import cast def klass_decorator[T](klass: type[T]) -> type[T]: class Wrapped(klass): ... return cast(type[T], Wrapped)
Good to know, thanks!
This is addressed in pyright 1.1.371.
Currently, Pyright can recognize valid type-expressions, take the following examples:
Valid:
Invalid
However, this doesn't apply to generics:
See this Pyright Playground example.
Mostly creating this to capture the fact that this is missing, but understandable if we want to avoid implementing support until there's more real feedback around it.