ruff/crates/red_knot_python_semantic/resources/mdtest/generics
Carl Meyer 4c3f389598
[red-knot] fix inheritance-cycle detection for generic classes (#17620)
## Summary

The `ClassLiteralType::inheritance_cycle` method is intended to detect
inheritance cycles that would result in cyclic MROs, emit a diagnostic,
and skip actually trying to create the cyclic MRO, falling back to an
"error" MRO instead with just `Unknown` and `object`.

This method didn't work properly for generic classes. It used
`fully_static_explicit_bases`, which filter-maps `explicit_bases` over
`Type::into_class_type`, which returns `None` for an unspecialized
generic class literal. So in a case like `class C[T](C): ...`, because
the explicit base is an unspecialized generic, we just skipped it, and
failed to detect the class as cyclically defined.

Instead, iterate directly over all `explicit_bases`, and explicitly
handle both the specialized (`GenericAlias`) and unspecialized
(`ClassLiteral`) cases, so that we check all bases and correctly detect
cyclic inheritance.

## Test Plan

Added mdtests.
2025-04-25 06:55:00 -07:00
..
classes.md [red-knot] fix inheritance-cycle detection for generic classes (#17620) 2025-04-25 06:55:00 -07:00
functions.md [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
legacy.md Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
pep695.md [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00
scoping.md [red-knot] Fix MRO inference for protocol classes; allow inheritance from subscripted Generic[]; forbid subclassing unsubscripted Generic (#17452) 2025-04-18 19:55:53 +00:00
variance.md [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00