Skip to content

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

Description

@sterliakov

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions