Skip to content

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

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
bzoracler opened this issue Aug 17, 2024 · 0 comments · Fixed by #18884 · May be fixed by coderabbit-test/mypy#2
Closed

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

bzoracler opened this issue Aug 17, 2024 · 0 comments · Fixed by #18884 · May be fixed by coderabbit-test/mypy#2
Labels
bug mypy got something wrong

Comments

@bzoracler
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
1 participant