Loading topic
int, str, list, dict, tuple), and can run scripts and install packages with pip. It also assumes you have seen the annotation syntax name: type, -> type, and name: type = value.4 min readint, str, list, dict, tuple), and can install packages with pip. It also assumes you have seen the annotation syntax name: type and -> type. Here you will install a static type checker, run it, an5 min readlist, dict, set, and tuple. It also assumes you have seen the basic name: type syntax and can run mypy or pyright. Here you learn how to describe what a collection holds, not only that it is a collection.4 min readname: str, -> int), that you know list[int] and dict[str, int], and that you can run mypy or pyright on a file. It covers how to say "this value is one of several types," and how to say "this value might be None."5 min readX | None unions, and run mypy or pyright on a file. Here you will learn how a checker turns a wide type such as str | None into a narrower one such as str, based on the checks in your code.4 min readdef f(x: int) -> str), use built-in generics such as list[int], and run mypy or pyright on a file. Python treats functions as values, so you can pass one to another function, store it in a dict, or return it. Callable is the annotation th4 min readX | None, built-in generics such as dict[str, list[int]], and Callable. It also assumes Python 3.10 or newer. Where a feature needs 3.12, the text says so.4 min readX | None unions, and run mypy or pyright on a script. It covers two tools from the typing module. Literal limits a value to specific constants. Final marks a name that must not be reassigned.4 min readint, str | None, and list[str], and you can run a checker such as mypy or pyright. Here you will see how annotations describe the attributes and methods of a class, and how dataclasses turns those annotatio4 min readlist[int] and X | None, run mypy or pyright, and know what Callable and Protocol are. You will learn how a TypeVar lets one function work with many types while keeping the relationship between its input and output typ4 min readX | None unions, and you have run mypy or pyright on a file. You do not need generics beyond what earlier chapters covered.3 min readdict[str, int] and str | None. It also assumes you have run mypy or pyright on a file. Examples use Python 3.11 or later, because NotRequired was added to typing in 3.11. On older versions, import it from typing_extensions.4 min readX | None unions, and know that the interpreter stores hints without enforcing them. It covers how to refer to a type that doesn't exist yet when Python reads the annotation.4 min readTypeVar, annotate collections such as list[int], and run mypy or pyright. A generic class applies the TypeVar idea to a whole class. Its methods and attributes share one or more type parameters, so a checker can track what a container h4 min readCallable, unions, Literal, and TypeVar, and that you can run mypy or pyright on a file. You will learn how @overload describes a function whose return type depends on its arguments, and when a simpler tool is the better choice.4 min readX | None, Any, object, and TypedDict. It covers how to add hints to code that has none, without a rewrite and without thousands of errors on day one.4 min read