Rule
UP046: non-pep695-generic-class
Purpose
Modernize generic class definitions to Python 3.12 PEP 695 syntax.
Example
# Before (old style)
from typing import Generic, TypeVar
T = TypeVar("T")
class Container(Generic[T]):
def __init__(self, item: T) -> None:
self.item = item
# After (Python 3.12 style)
class Container[T]:
def __init__(self, item: T) -> None:
self.item = item
Auto-fix
✅ Available
Notes
- Part of Python 3.12 modernization effort
- Eliminates boilerplate TypeVar definitions
- Cleaner and more readable generic class syntax
JIRA Issue: BA-4027