mypy
mypy copied to clipboard
MyPy fails to check `TypedDict.update` call with only explicit keyword arguments
Bug Report
Calls to TypedDict.update don't type-check, even if all the updates are specified using keyword arguments.
To Reproduce
Type-check this program:
from typing import TypedDict
class Args(TypedDict, total=False):
a: int
b: str
args = Args()
args.update(a=123, b="abc")
Expected Behavior
The code should type-check, since all arguments to TypedDict.update were passed as keyword arguments, and the types of the arguments are correct.
Actual Behavior
$ mypy test.py
test.py:8: error: Unexpected keyword argument "a" for "update" of "TypedDict" [call-arg]
/lib/python3.10/site-packages/mypy/typeshed/stdlib/typing.pyi:894: note: "update" of "TypedDict" defined here
test.py:8: error: Unexpected keyword argument "b" for "update" of "TypedDict" [call-arg]
/lib/python3.10/site-packages/mypy/typeshed/stdlib/typing.pyi:894: note: "update" of "TypedDict" defined here
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.9.0
- Mypy command-line flags: none (just ran
mypy test.py) - Mypy configuration options from
mypy.ini(and other config files): none (no special configuration) - Python version used: 3.10
Had the same issue on 1.10.1 on python 3.12 just now. Pylance seems to handle this specific case better.