mirror of
https://github.com/astral-sh/ruff
synced 2026-01-23 06:20:55 -05:00
## 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.
Markdown files within the mdtest/ subdirectory are tests of type inference and type checking;
executed by the tests/mdtest.rs integration test.
See crates/red_knot_test/README.md for documentation of this test format.