Loading topic
list[int] and str | None, and have run a static type checker such as mypy or pyright. The examples use the Python 3.12 syntax def f[T](...), so they need Python 3.12 or newer. Older Python versions use a d6 min readlist[int] and str | None, and you know that checkers like mypy or pyright read those annotations without running your program. You need this s5 min readlist[int], and have run a static checker such as mypy or pyright. It uses the classic TypeVar and Generic style first, then the Python 3.12 syntax. The syntax itself is covered in the next chapter.5 min readTypeVar and Generic, as shown in the earlier chapters. It also assumes you can run Python 3.12 or newer and a type checker such as mypy or pyright. The chapter covers how the new syntax declares type parameters, how to convert old code,5 min readdef first[T](items: Sequence[T]) -> T. It also assumes you know that mypy or pyright checks annotations without running your program. Examples use the Python 3.12 syntax, and the legacy TypeVar forms appear alongside for older cod5 min readclass Box[T] or Generic[T]. It also assumes you know that a static checker such as mypy or pyright reads your annotations without running the program. Here you will learn how the relationship between two types carries over to generic types 5 min readdef f[T] and class C[T], and that you know what a type checker such as mypy or pyright reports. It covers the type statement from Python 3.12. The statement gives a name to a type expression, can take its own type parameters5 min readtyping.Protocol), generic functions and classes, and the def f[T] and class C[T] syntax from Python 3.12. It builds on the variance chapter. If "covariant" and "contravariant" are unfamiliar, read that chapter first.5 min readdef f[T] syntax from earlier chapters and that you run a static checker such as mypy or pyright. The code uses Python 3.12 syntax.4 min read[T] syntax, and that you know what bounds and constraints do. It also assumes you run a static checker such as mypy or pyright. Type parameter defaults are a Python 3.13 feature, and your checker must support them (specified5 min readdef f[T], class Box[T]) and can read tuple[int, str] annotations. You also need a static checker such as mypy or pyright, because the guarantees here come from the checker and not from the interpreter. The [*Ts] syntax nee5 min readdef f[T] and class C[T] syntax from the earlier chapters. It also assumes you know that ordinary annotations are normally evaluated when a def statement runs. Here you will see where a type parameter name is visible. You will also see which parts of a gene6 min readdef f[T] and class C[T], know that mypy or pyright check annotations without running the program, and have seen list[int] in annotations. The e6 min read