Skip to content

TypedDict not recognised as valid dict when passed as parameter to a function #12934

@berzi

Description

@berzi

Bug Report

Mypy reports an error when a TypedDict is passed as an argument to a function that is annotated as accepting dicts more generally.

To Reproduce

class TestDict(TypedDict):
    a: int


def myfunc(test: dict):
    print(test)


myfunc(TestDict(a=2))

Note that:

>>> type(TestDict(a=2))
<class 'dict'>

Expected Behavior

No error.

Actual Behavior

error: Argument 1 to "myfunc" has incompatible type "TestDict"; expected "Dict[Any, Any]"  [arg-type]
    myfunc(TestDict(a=2))
           ^

Your Environment

  • Mypy version used: 0.960 (compiled: yes)
  • Python version used: 3.9.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions