Type System Reference — typing documentation
Defining generic classes · Defining subclasses of generic classes · Generic functions · Generic methods and generic self · Automatic self types using typing.Self ...
Defining generic classes · Defining subclasses of generic classes · Generic functions · Generic methods and generic self · Automatic self types using typing.Self ...
Typing Python Libraries. Why provide type annotations?Inline type annotations simply refers to the use of annotations within your .py files. In contrast, with type stub files, type information lives in separate .pyi files; see Stub files and Writing and Maintaining Stub Files for more details.
type[T] where T is a type variable is allowed when annotating the first argument of a class method (see the relevant section). Any other special forms like ...
The term “argument” refers to a value passed to a function when it is called. Python supports five kinds of parameters: positional-only, keyword-only, standard (positional or keyword), variadic positional (*args), and variadic keyword (**kwargs).
For return values, prefer concrete types ( list , dict , etc.) for concrete implementations. The return values of protocols and abstract base classes must be ...
All features from the typing module of the latest released Python version that use supported syntaxComments, including type declaration (# type: X) and error suppression (# type: ignore) comments
(Note that one can explicitly subclass a protocol and still not implement it if a protocol attribute is set to None in the subclass. See Python data model for ...
The Python type system also uses ... within Callable types and within tuple[Any, ...] (see Tuples) to indicate a statically unknown component of a type. The ...
All methods from the parent type will be directly inherited by the literal type. So, if we have some variable foo of type Literal[3] it's safe to do things like ...