mypy icon indicating copy to clipboard operation
mypy copied to clipboard

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

Open bzoracler opened this issue 1 year ago • 0 comments

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

bzoracler avatar Aug 17 '24 02:08 bzoracler