Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyPy fails to check TypedDict.update call with only explicit keyword arguments #17750

Open
gareth-rees opened this issue Sep 9, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@gareth-rees
Copy link

gareth-rees commented Sep 9, 2024

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
@gareth-rees gareth-rees added the bug mypy got something wrong label Sep 9, 2024
@Alexandre-SCHOEPP
Copy link

Had the same issue on 1.10.1 on python 3.12 just now. Pylance seems to handle this specific case better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants