-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Use visit_annotation for type alias value
#17495
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
Conversation
This was a follow up task from astral-sh#17180 (comment) separated into this PR.
|
Yeah, I think this is happening because we |
|
We'll need to update other visitors as well i.e., |
MichaReiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried about this change, specifically that enter_node is now called twice. This can break existing visitiors that override enter_node and assume that it is only called exactly once (Which I think is true for the formatter).
It seems to me that SourceOrderVisitor::visit_annotation isn't overriden anywhere. That makes me wonder if we should just remove the method for now and simply call visit_expr.
I think we should also update the Visitor implementation to call visit_annotation
ruff/crates/ruff_python_ast/src/visitor.rs
Line 185 in 8a4158c
| visitor.visit_expr(value); |
|
Thanks for the link I somehow didn't find that. Do you mean we can remove the We are not overriding About the breaking change you mentioned I don't understand in what situation it can break(Should I look for an |
|
Here's an example of an visitor that I'm worried that would break: ruff/crates/ruff_python_formatter/src/comments/visitor.rs Lines 73 to 112 in 8a4158c
But there are probably others. Any visitor that internally maintains a stack of "parents" is affected by this because we may end up with a situation where the
Yes, I think we can simply remove it entirely because it's unused (I think)
If that's the case, yes, I'd remove it too |
|
I'll close this due to inactivity. If anyone is interested in picking this up again, feel free to submit a new PR and reference this PR in the summary. Thanks @Glyphack for exploring this. |
Summary
This was a follow up task from #17180 (comment) separated into this PR.
Test Plan
The tests run. There was already a test for type alias that I updated.
TBH I don't understand why in the representation the
ExprSubscriptis repeated.But I created a sample test to check this behavior and it happens everytime
visit_annotationis used:for: