Generate TypedDict from function's keyword arguments
问题 foo.py : kwargs = {"a": 1, "b": "c"} def consume(*, a: int, b: str) -> None: pass consume(**kwargs) mypy foo.py : error: Argument 1 to "consume" has incompatible type "**Dict[str, object]"; expected "int" error: Argument 1 to "consume" has incompatible type "**Dict[str, object]"; expected "str" This is because object is a supertype of int and str , and is therefore inferred. If I declare: from typing import TypedDict class KWArgs(TypedDict): a: int b: str and then annotate kwargs as KWArgs ,