Skip to content

Cyclic definition error when defaulting TypeVar on base class to subclass #20698

Description

@randolf-scholz
fromtypingimportProtocolclassSupportsComparison[CompatT, TruthT](Protocol):
def__gt__(self, other: CompatT, /) ->TruthT: ...
def__ge__(self, other: CompatT, /) ->TruthT: ...
def__lt__(self, other: CompatT, /) ->TruthT: ...
def__le__(self, other: CompatT, /) ->TruthT: ...
classScalar[CompatT, TruthT=Bool]( # ❌️ Cannot resolve name "Bool"SupportsComparison[CompatT, TruthT],
): ...
# Specialized Scalar TypesclassBool(Scalar): ...
classInt(Scalar): ...
classFloat(Scalar): ...
classComplex(Scalar): ...

mypy complains with

py:9:30: error: Cannot resolve name "Bool" (possible cyclic definition) [misc]
py:9:30: error: TypeVar "default" must be a type [misc]

pyright, ty and pyrefly report no errors.

tested with mypy 1.19.1 on python 3.14.2

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