python / python/mypy

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

Open
#17,750 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproducer and compare the reported signature in typeshed/stdlib/typing.pyi with how mypy handles TypedDict.update calls. Add regression coverage for keyword-only updates and verify that running mypy on the example reports no errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.