-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
We have a class hierarchy where Base has a nested class Params, and derived classes can define their own Params that extends Base.Params. Params is a TypedDict. When accessing Derived.Params
on a class that does not define its own params, this of course obtains Base.Params
. But mypy gets confused and doesn't see the keys defined on the TypedDict.
To Reproduce
https://gist.github.com/mypy-play/e3f7a74856e6710fdf2c70113a2b1e19
from typing_extensions import TypedDict
class Base:
class Params(TypedDict, total=False):
name: str
class Derived(Base):
pass
class DerivedOverride(Base):
class Params(Base.Params):
pass
bob1 = Base.Params(name="Robert")
bob2 = Derived.Params(name="Robert") # spurious error here!
bob3 = DerivedOverride.Params(name="Robert")
Expected Behavior
The gist above typechecks cleanly.
Actual Behavior
main.py:16: error: Unexpected keyword argument "name" for "Params" [call-arg]
/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/typeshed/stdlib/builtins.pyi:110: note: "Params" defined here
Found 1 error in 1 file (checked 1 source file)
https://mypy-play.net/?mypy=1.14.1&python=3.12&gist=e3f7a74856e6710fdf2c70113a2b1e19
Your Environment
Defaults from mypy Playground (latest version = 1.14.1 as of this writing).