为什么mypy在TypedDict调用update方法时不通过
Why doesn't mypy pass when TypedDict calls update method
示例:
from typing import TypedDict
class MyType(TypedDict):
a: int
b: int
t = MyType(a=1, b=2)
t.update(b=3)
mypy toy.py
抱怨
toy.py:9:1: error: Unexpected keyword argument "b" for "update" of "TypedDict"
Found 1 error in 1 file (checked 1 source file)
这似乎是 mypy
的一个已知未决问题:https://github.com/python/mypy/issues/6019
现在,如果您希望 mypy
不被这个错误打扰,您需要告诉它忽略它:
t.update(b=3) # type: ignore[call-arg]
示例:
from typing import TypedDict
class MyType(TypedDict):
a: int
b: int
t = MyType(a=1, b=2)
t.update(b=3)
mypy toy.py
抱怨
toy.py:9:1: error: Unexpected keyword argument "b" for "update" of "TypedDict"
Found 1 error in 1 file (checked 1 source file)
这似乎是 mypy
的一个已知未决问题:https://github.com/python/mypy/issues/6019
现在,如果您希望 mypy
不被这个错误打扰,您需要告诉它忽略它:
t.update(b=3) # type: ignore[call-arg]