Skip to content

TypedDict arguments are not recognized if a base class's nested class is accessed via a subclass #18600

@camillol

Description

@camillol

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions