Summary
The rule non-pep695-generic-class doesn't seem to cover a use case where you define a TypeVar in a module which is imported in several other files.
For example, imagine I have a file
my_types.py
with
from typing import TypeVar
CustomNumber = TypeVar("CustomNumber", bound=int)
and two files a.py with
from mytypes import CustomNumber
class A(Generic[CustomNumber]):
...
and b.py with
from mytypes import CustomNumber
class B(Generic[CustomNumber]):
...
If I want to change CustomNumber to have an upper bound of float I would only need to change in one location. If I would adhere to PEP695 I would need to remove the my_types.py file and refactor the code to e.g.
class A[CustomNumber: int]():
...
and
class B[CustomNumber: int]():
...
thus breaking code reproducibility if I would want to change the upper bound. This could lead to code inconsistencies
I deliberately made the example a bit dummy and trivial but I think it makes the issue clear :-).
Summary
The rule non-pep695-generic-class doesn't seem to cover a use case where you define a
TypeVarin a module which is imported in several other files.For example, imagine I have a file
my_types.pywith
and two files
a.pywithand
b.pywithIf I want to change
CustomNumberto have an upper bound offloatI would only need to change in one location. If I would adhere to PEP695 I would need to remove themy_types.pyfile and refactor the code to e.g.and
thus breaking code reproducibility if I would want to change the upper bound. This could lead to code inconsistencies
I deliberately made the example a bit dummy and trivial but I think it makes the issue clear :-).