Skip to content

Alias of a TypedDict not recognized as a TypedDict base #18851

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

Closed
sterliakov opened this issue Mar 29, 2025 · 0 comments
Closed

Alias of a TypedDict not recognized as a TypedDict base #18851

sterliakov opened this issue Mar 29, 2025 · 0 comments
Labels
bug mypy got something wrong topic-typed-dict

Comments

@sterliakov
Copy link
Collaborator

sterliakov commented Mar 29, 2025

Bug Report

Follow-up after #18850 discovery.

When a base TypedDict is defined in sys.version_info branches, mypy does not pick it as a proper TypedDict base.

To Reproduce

from typing import Required, TypedDict

class Base(TypedDict):
    foo: int

BestBase = Base

class Child(BestBase):
    baz: Required[int]  # E: Required[] can be only used in a TypedDict definition

Or playground

Expected Behavior

sys.version_info is a recognized guard, so Child should be treated as regular TypedDict.

Actual Behavior

e.py:9: error: Required[] can be only used in a TypedDict definition  [valid-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0 and current master
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12
@sterliakov sterliakov added bug mypy got something wrong topic-typed-dict labels Mar 29, 2025
@sterliakov sterliakov changed the title TypedDict defined in sys.version_info guards is not recognized as a TypedDict base Alias of a TypedDict not recognized as a TypedDict base Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

No branches or pull requests

1 participant