Loading topic
list[int] and str | None. You don't need to have run a type checker yet. Later chapters assume you are comfortable with the ideas here.3 min readlist[int] and str | None, and know that a checker like mypy or pyright reads those annotations without running your code. It uses the Python 3.12 syntax for type parameters.2 min readlist[int] and str | None, and know that tools like mypy or pyright check annotations without running your program. You will meet the pre-3.12 way to write generics. You will still see it in most existing co2 min readlist[int] and that mypy or pyright checks them without running your code. The previous chapters covered generic functions and the classic TypeVar.2 min readlist[int]. It also assumes you know what a generic function does, and that you run a checker such as mypy or pyright. You also need Python 3.12 or later to run the examples.2 min readdef f[T], class C[T]) and that you run a static checker such as mypy or pyright. An unrestricted type parameter lets the checker assume almost nothing about T. Bounds and constraints give it more to w2 min readclass Box[T], know that type arguments are checked only by static tools like mypy or pyright, and understand subtyping (int is accepted where float is expected under the typing rules).2 min read[T] syntax, and that you run a static checker such as mypy or pyright. It covers how to name a type, including a generic or recursive one, with the type statement.2 min read[T] syntax, and the basic idea of variance. A generic protocol combines two ideas. A protocol describes a type by the methods it has. A type parameter lets those methods mention other types.2 min readfunctools.wraps works, and how to write a generic function with def f[T]. It uses the Python 3.12 type parameter syntax.2 min readclass C[T], def f[T]) and that you run a static type checker such as mypy or pyright. Type parameter defaults come from PEP 696 and are available in the language from Python 3.13.3 min read[T] syntax and that you know what a type checker such as mypy or pyright does. A TypeVar stands for one type. A TypeVarTuple stands for any number of types, including zero.2 min readdef f[T], class C[T], type X = ...). It covers where a type parameter's name is visible and when Python evaluates the expressions attached to it.3 min read[T] syntax and that you run a checker such as mypy or pyright. Here you will see which generic information Python keeps when the program runs and which information only the checker uses.2 min read