Skip to content

Enable UP046: Simplify generic class syntax (Python 3.12) #8234

@HyeockJinKim

Description

@HyeockJinKim

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions