Back to Ruff

Cyclic Class Definition

crates/ty_python_semantic/resources/lint_docs/cyclic-class-definition.md

0.15.18534 B
Original Source

What it does

Checks for class definitions in stub files that inherit (directly or indirectly) from themselves.

Why is it bad?

Although forward references are natively supported in stub files, inheritance cycles are still disallowed, as it is impossible to resolve a consistent method resolution order for a class that inherits from itself.

Examples

foo.pyi:

pyi
class A(B): ...  # error
class B(A): ...  # error