Conceptual
Login

Generic Types in Python 3.12

Python's type system (PEP 484) supports generic types, which parameterize container-like types (e.g., lists, dicts, custom classes) with a type variable so that the relationship between input and output types is preserved and checkable by static analysis, unlike `Any`, which disables type checking entirely. Generics are formally expressed via type variables (historically `TypeVar`, and since Python 3.12 the native `type` statement and bracket syntax), and can be constrained using upper bounds (a class or tuple of classes) to restrict which types may satisfy the generic parameter. This concept belongs to the domain of static type systems within programming language theory, specifically type annotations and generic programming as applied in Python's typing module.