Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] No cyclic-class-def diagnostics for subclasses of cyclic classes #15561

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wooly18
Copy link
Contributor

@wooly18 wooly18 commented Jan 17, 2025

Summary

Resolves #14223

Test Plan

cargo nextest run

@wooly18 wooly18 marked this pull request as ready for review January 17, 2025 22:33
Copy link
Contributor

github-actions bot commented Jan 17, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@wooly18 wooly18 marked this pull request as draft January 17, 2025 22:54
@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Jan 17, 2025
@wooly18 wooly18 marked this pull request as ready for review January 17, 2025 23:10
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you for the contribution!

The algorithm looks good, my only comments are on naming and clarity. Apologies, this is slightly bike-sheddy. I think the Option<bool> return type (and its semantics: Some if there is a cycle, else None, inner bool is true if the class itself is a participant in the cycle) are too non-obvious. I would prefer an explicit InheritanceCycle enum with variants Inherited and Participant (with doc comments clarifying the meaning of each), and return Option<InheritanceCycle> instead. We can define a method like is_participant() to make the usage of this enum in the if test for the diagnostic a bit more ergonomic.

I'm also not sure that is_involved_in_cyclic_definition adds enough clarity to justify its length. I'm guessing you renamed from is_cyclically_defined because that seems to imply the definition of this class itself is part of the cycle? I agree with that. I'd suggest maybe just inheritance_cycle() as the method name, leading to usages looking like class.inheritance_cycle().is_some(), which reads pretty naturally?

@AlexWaygood wrote this code and may also have thoughts, not sure if he'll be able to offer them before Monday, though.

@wooly18
Copy link
Contributor Author

wooly18 commented Jan 18, 2025

Thanks for the feedback! The name changes sound good to me and I'm happy to make them soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[red-knot] Too many diagnostics for subclasses of cyclic classes
3 participants