Skip to content

Allow TypedDict functional syntax as base class #16701

@anniel-stripe

Description

@anniel-stripe

Bug Report

Using TypedDict's alternative functional syntax as a base class produces a Unsupported dynamic base class "TypedDict" [misc] error.

To Reproduce
Gist: https://mypy-play.net/?mypy=latest&python=3.12&gist=78872722658fe7bd5042cba6318b0432

Expected Behavior

I'd expect a call to TypedDict to be allowed to be used as a base class:

class Params(
        TypedDict(  # This should work
            "Params",
            {"is": NotRequired["str"]},
        ),
    ):
        pass
        
a: Params = { "is": "a" }  # Produces misleading error

Actual Behavior

Instead, it produces the following errors:

main.py:4: error: Unsupported dynamic base class "TypedDict"  [misc]
main.py:11: error: Incompatible types in assignment (expression has type "dict[str, str]", variable has type "Params")  [assignment]

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions