Skip to content

Constrained TypeVar default causes false positive error if the default is a TypedDict type #17686

Description

@bzoracler

Bug Report, To Reproduce, & Expected Behaviour

An error occurs when defining a constrained type variable where the default is a TypedDict type. See mypy Playground:

import typing as t

class A(t.TypedDict):
    a: int

T = t.TypeVar("T", int, A, default=A)  # E: TypeVar default must be one of the constraint types  [misc]

class C(t.Generic[T]): ...

# Using the type variable still correctly gets its default
reveal_type(C())  # OK: C[TypedDict("A", {"a": int})]

Expected Behavior

No errors

Your Environment

  • Mypy version used: 1.10.1, 1.11.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10, 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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions