-
-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Context and Problem
I saw there was a debate on a recently merged PR about whether or not to support pre-PEP 695 generics (i.e., which use Generic and TypeVar).
My understanding is that these are not currently supported. One particular consequence are spurious warnings. For example, for the following class definition:
T = TypeVar("T", covariant=True)
P = TypeVar("P", contravariant=True)
@dataclass(frozen=True)
class OpaqueSpace(Generic[P, T], dp.Space[T]):
"""
Type Parameters:
P: Type parameter for the ambient inner policy type.
T: Type parameter for the element type.
"""I get the spurious warning:
WARNING - griffe: src/delphyne/stdlib/opaque.py:29: Type parameter 'P' does not appear in the class signature
The Case for Supporting Pre-PEP 695 Generics
One argument for supporting pre-PEP 695 generics is that the features they offer are not subsumed by PEP 695. In particular, PEP 695 does not allow specifying the variance of type variables. Type checkers can infer this information most of the time, but there are also cases where the use of TypeVar and Generic cannot be avoided (this is the case in one of my projects).
If (partial) support for Pre-PEP 695 Generics can be added without excessive effort, it would therefore be a worthwhile addition.