Skip to content

generic dataclass with default (and typevar default) #18812

@asottile-sentry

Description

@asottile-sentry

Bug Report

this is the sameish as #12962 however now that PEP 696 exists I expect this to work

To Reproduce

from typing import Literal
from dataclasses import dataclass

@dataclass
class D[TBool: (Literal[True], Literal[False]) = Literal[True]]:
    val: TBool = True


reveal_type(D())
reveal_type(D(True))
reveal_type(D(False))

Expected Behavior

I expect no errors however

Actual Behavior

t3.py:6: error: Incompatible types in assignment (expression has type "Literal[True]", variable has type "TBool")  [assignment]
t3.py:9: note: Revealed type is "t3.D[Literal[True]]"
t3.py:10: note: Revealed type is "t3.D[Literal[True]]"
t3.py:11: note: Revealed type is "t3.D[Literal[False]]"
Found 1 error in 1 file (checked 1 source file)

(the reveal types are all correct -- mostly just to demonstrate that the idea works)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-696TypeVar defaults

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions