Loading topic
dict[str, Any]. It tells a type checker almost nothing, so many mistakes go unreported until the code runs. This chapter shows where that happens and intr3 min readint and list[str]. It also assumes you know that a static checker such as mypy or pyright reads annotations separately from running the code.2 min readint and str, and that a static type checker such as mypy or pyright reads annotations separately from running the code. It also assumes you have seen TypedDict from the previous chapter.3 min readTypedDict with the class syntax, know basic type hints such as str and Optional, and run a static checker such as mypy or pyright. The checker reads these rules. Python itself never enforces them.1 min readLiteral[...] annotation and run a checker such as mypy or pyright. Here you will name literal types, combine them, and learn which kinds of values Literal accepts.2 min readTypedDict as in the earlier chapters.2 min readLiteral annotations and run a checker such as mypy or pyright. It also assumes you know if/elif chains. Python 3.11+ is needed for assert_never from typing. On older versions, import it from typing_extensions.2 min readTypedDict and use Literal, and that you run a checker such as mypy or pyright. The examples use Python 3.11 or newer for assert_never.2 min readTypedDict. You should also know how NotRequired and total=False mark optional keys, and that a type checker such as mypy or pyright checks these annotations separately from running the code.2 min readTypedDict and use NotRequired, as covered in the earlier chapters. You should also know that a type checker such as mypy or pyright reads these declarations, and Python itself does not enforce them.2 min readTypedDict, know the difference between required and NotRequired keys, and run a checker such as mypy or pyright. Here you learn when a checker accepts one TypedDict where another is expected, and why a TypedDict does not fit dict[str, Any].2 min readtotal=False makes keys optional, and that a type checker such as mypy or pyright checks annotations without running the code.2 min readTypedDict with the class syntax, know that NotRequired marks an optional key, and run a static checker such as mypy or pyright. ReadOnly is available from typing in Python 3.13 and later. On older versions, import it from typing_extensions.3 min readTypedDict and Literal annotations and know that a type checker such as mypy or pyright runs separately from your program. You have seen that a TypedDict is an ordinary dict at runtime. Here you will use that fact to pick the right tool.2 min read