Loading topic
dict[str, Any]. This chapter shows what that annotation lets through, why that matters, and which two tools in the typing module ad6 min readint, str, list[str], and Optional. Finally, it assumes you know that a static type checker such as mypy or pyright reads your annotations separately from Python runni5 min readstr, int and Optional. It also assumes you know that a checker such as mypy or pyright reads annotations without running your program. If those ideas are new, review them first.5 min readTypedDict with the class syntax, that you know Optional and Literal at a basic level, and that you run a static checker such as mypy or pyright separately from your code. The examples use NotRequired and Required, which live in typing from Pyth5 min readLiteral["r", "w"] from the previous chapter. It also assumes you have run a checker such as mypy or pyright. Here you will name a set of constants once, combine sets, and learn which kinds of values Literal accepts. You will also see how to turn an or5 min readTypedDict and4 min readLiteral["a", "b"] and give it a name with an alias. Here you will see how a checker narrows a Literal typ5 min readTypedDict and a Literal alias, and that you know a static type checker such as mypy or pyright reads annotations separately from running the code. It builds on the earlier chapters about required keys and about narrowing Literal values.5 min readtotal, why overriding a key usually fails, and what inheritance does at runtime. It assumes you can define a basic TypedDict, you know total=False, Required and `NotRequi5 min readTypedDict, and that you know total, Required and NotRequired from the earlier chapters. You should also know that a type checker such as mypy or pyright reads annotations separately from running the code. The examples use NotRequired, so th5 min readtotal and NotRequired control which keys are optional, and run mypy or pyright separatel5 min read**kwargs works, how to define a TypedDict, and how total=False, Required and NotRequired mark optional keys. It also assumes you run a static checker such as mypy or pyright. Unpack with a TypedDict is a typing feature only, so the checker is what enfo5 min readTypedDict, mark keys with NotRequired, and read the output of a type checker such as mypy or pyright. It covers ReadOnly, which lets a TypedDict declare that some keys must not be changed after the dictionary is created.5 min readTypedDict and Literal. You should know that a type checker such as mypy or pyright reads annotations separately from the running program. You should also be comfortable with classes and the dataclasses module. By the end you will be ab5 min read