Generics — typing documentation
A list[str] isn't just a list, it's a list of strings. Types with type parameters like this are called generic types. You can define your own generic classes ...
A list[str] isn't just a list, it's a list of strings. Types with type parameters like this are called generic types. You can define your own generic classes ...
Distributing type information. Stub files. Syntax. Supported Constructs. Value Expressions.Class definition syntax follows general Python syntax, but type checkers are expected to understand only the following constructs in class bodies
In general, a function input parameter should be annotated with the widest possible type supported by the implementation. For example, if the implementation requires the caller to provide an iterable collection of strings, the parameter should be annotated as Iterable[str], not as list[str].
Predefined protocol reference. Credits. Typing Best Practices. Introduction.Improving Type Completeness. typing Module Documentation. This Page.