zyxue
zyxue

Reputation: 8908

Why doesn't mypy pass when TypedDict calls update method

Example:

from typing import TypedDict

class MyType(TypedDict):
    a: int
    b: int

t = MyType(a=1, b=2)

t.update(b=3)

mypy toy.py complains

toy.py:9:1: error: Unexpected keyword argument "b" for "update" of "TypedDict"
Found 1 error in 1 file (checked 1 source file)

Upvotes: 10

Views: 670

Answers (1)

Da Chucky
Da Chucky

Reputation: 783

It appears this is a known open issue for mypy: https://github.com/python/mypy/issues/6019

For now if you want mypy to not bother you with this error, you'll need to tell it to ignore it:

t.update(b=3)  # type: ignore[call-arg]

Upvotes: 6

Related Questions