Specification for the Python type systemΒΆ
Contents:
- The Python Type System
- Meta-topics
- Type system concepts
- Type annotations
- Type forms
- Special types in annotations
- Generics
- Introduction
- User-defined generic types
- Scoping rules for type variables
- Instantiating generic classes and type erasure
- Arbitrary generic types as base classes
- Abstract generic types
- Type variables with an upper bound
- Variance
- ParamSpec
- TypeVarTuple
- Defaults for Type Parameters
Self- Variance Inference
- Type qualifiers
- Class type assignability
- Type aliases
- Literals
- Protocols
- Terminology
- Defining a protocol
- Protocol members
- Explicitly declaring implementation
- Merging and extending protocols
- Generic protocols
- Recursive protocols
- Self-types in protocols
- Assignability relationships with other types
- Unions and intersections of protocols
type[]and class objects vs protocolsNewType()and type aliases- Modules as implementations of protocols
@runtime_checkabledecorator and narrowing types byisinstance()
- Callables
- Constructors
- Constructor Calls
- Metaclass
__call__Method __new__Method__init__Method- Classes Without
__new__and__init__Methods - Constructor Calls for type[T]
- Specialization During Construction
- Consistency of
__new__and__init__ - Converting a Constructor to Callable
- Metaclass Constructors
- The
typeConstructor - Class Statements
- The
__init_subclass__()Method
Overloads- Exceptions
- Dataclasses
- Typed dictionaries
- Tuples
- Named Tuples
- Enumerations
- Type narrowing
- Type checker directives
- Distributing type information
- Historical and deprecated features
- Glossary