Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
typing.Never is the bottom type in Python’s static type system. Introduced in Python 3.11 (PEP 673), it represents a type that contains no values. Because it has no instances, a variable or parameter annotated with Never can never be assigned a value at runtime without violating static type constraints.
In type theory, a bottom type is the strict subtype of all other types. This means Never is implicitly compatible with int, str, list, or any user-defined class. It is the structural inverse of object, which is the true top type (the strict supertype of all types). This contrasts with typing.Any, which is the dynamic type that bypasses type checking by acting as both a supertype and a subtype to all types to facilitate gradual typing.
Exhaustiveness Checking
The primary application ofNever in static type analysis is exhaustiveness checking. Using the typing.assert_never() function, developers can statically verify that all possible cases in a match statement or a Union have been handled.
assert_never() is typed to accept an argument of type Never. If a type checker determines that a branch of code is reachable (meaning the variable has not been narrowed down to Never), passing that variable to assert_never() will trigger a static type error.
Relationship with NoReturn
Never and typing.NoReturn are treated as strictly equivalent by static type checkers (such as mypy or pyright). They share the exact same internal semantics.
Never was introduced to provide a more mathematically accurate and context-independent name for the bottom type. While NoReturn conceptually implies a function’s return signature (indicating a function that halts execution or loops infinitely), Never is semantically appropriate for any type hint context, including variable annotations, argument types, and generic type parameters.
Structural Properties
- Uninstantiable: There is no valid Python object that satisfies the
Nevertype. - Universal Subtype: Because it is the bottom type, a function returning
Nevercan be safely used in contexts expecting a function returning any other type (e.g.,Callable[[], int]can accept aCallable[[], Never]). - Intersection Identity: In type algebra, the intersection of any type
TandNeverevaluates toNever. - Union Identity: The union of any type
TandNeverevaluates toT(e.g.,Union[int, Never]simplifies toint).
Master Python with Deep Grasping Methodology!Learn More





