Loading topic
int, str, list, dict, and tuple. You should also be able to run a script and install packages with pip.2 min readname: type annotation syntax. You should also be able to run a checker such as mypy or pyright.2 min readname: str, -> int), use built-in generics like list[int], and have run a static checker such as mypy or pyright. Type hints are not enforced at runtime, so everything below is reported by the checker, not by Python.2 min readX | None unions, and run mypy or pyright on a file. Narrowing is how a static checker works out that a wide type is really a narrower one at a given line.2 min readlist[int] and X | None, and run mypy or pyright. It covers how to describe a function that is passed to another function.2 min readstr | None, and annotate callables with Callable. Examples use Python 3.12 or newer unless noted.2 min readX | None unions, and run mypy or pyright on a file. Both tools are static checkers: they read your code without running it. Literal and Final give them two more facts to check: which exact values a variable may hold, and w2 min readname: type syntax for variables and parameters, and have run mypy or pyright on a file.2 min readlist[int], and run mypy or pyright on a file.2 min readstr and list[int], and run a static checker like mypy or pyright. A static checker is a tool that reads your code and reports type mismatches without running it.2 min readdict[str, int], and that you have run a static checker like mypy or pyright. It covers how to type a dictionary whose keys are fixed and whose values have different types.2 min readX | None, and define classes. It covers what happens when an annotation names a type that does not exist yet.2 min readTypeVar, annotate collections such as list[int], and run mypy or pyright.2 min readX | None unions, and run mypy or pyright. It also assumes you have seen TypeVar.2 min readX | None values. It covers how to add hints to code that has none, without stopping the team's work.2 min read