Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TypedDict functional syntax as base class #16701

Closed
anniel-stripe opened this issue Dec 22, 2023 · 0 comments · Fixed by #16703
Closed

Allow TypedDict functional syntax as base class #16701

anniel-stripe opened this issue Dec 22, 2023 · 0 comments · Fixed by #16703

Comments

@anniel-stripe
Copy link
Contributor

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
@anniel-stripe anniel-stripe added the bug mypy got something wrong label Dec 22, 2023
@AlexWaygood AlexWaygood added topic-typed-dict feature and removed bug mypy got something wrong labels Dec 22, 2023
hauntsaninja pushed a commit that referenced this issue Jan 14, 2024
Fixes #16701

This PR allows `TypedDict(...)` calls to be used as a base class. This
fixes the error emitted by mypy described in
#16701 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants