目录 例子 例子 from typing import TypedDict class User(TypedDict): name: str age: int user1: User = {"name": "Alice", "age": 30} user2: User = {"name": "Alice", "age": 30, "role": "admin"} # Extra key 'role' for TypedDict 'User' from typing import TypedDict class HookspecOpts(TypedDict): firstresult: bool historic: bool warn_on_impl: Warning | None warn_on_impl_args: Mapping[str, Warning] | None opts: HookspecOpts = { "firstresult": firstresult, "historic": historic, "warn_on_impl": warn_on_impl, "warn_on_impl_args": warn_on_impl_args, }