-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Format PatternMatchClass
#6860
Format PatternMatchClass
#6860
Conversation
I don't know how to solve the conflict for the |
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.
So many removed lines
...python_formatter/tests/snapshots/black_compatibility@py_310__pattern_matching_extras.py.snap
Outdated
Show resolved
Hide resolved
join.finish() | ||
}); | ||
|
||
write!(f, [cls.format(), parenthesized("(", &items, ")")]) |
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.
Try adding an extra group around items
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.
Would the function group
work here?
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.
Yes, group(&items) should do the trick if I'm not mistaken
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.
Nothing changed for this crates/ruff_python_formatter/tests/snapshots/black_compatibility@py_310__pattern_matching_extras.py.snap
file when using group
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.
See my comment below. This is fine, assuming we're talking about the same mismatch.
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.
This looks good to me. Thank you.
Could you add one test case to
that tests for the following weird comment placement
match x:
case (
Point2D
# awkward
(x = 2)
: ...
- ): | ||
+ case NOT_YET_IMPLEMENTED_PatternMatchClass(0, 0): | ||
+ normal=x, | ||
+ perhaps=[list, {"NOT_YET_IMPLEMENTED_PatternMatchMapping": _, 2: _}] as y, |
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.
Okay, the problem here is that PatternMatchMapping
isn't yet implemented and the text emitted by the "fake" implementation is much longer than the expected string.
We can ignore this.
join.finish() | ||
}); | ||
|
||
write!(f, [cls.format(), parenthesized("(", &items, ")")]) |
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.
See my comment below. This is fine, assuming we're talking about the same mismatch.
join.nodes(patterns.iter()); | ||
} | ||
|
||
if !kwd_attrs.is_empty() { |
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.
Do we need the if !kwd_attrs.is_empty()
?
# trailing | ||
# trailing | ||
): | ||
... |
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.
Could you add something like
match a:
case A(
b # b
= # c
2 # d
# e
):
pass
with the left hand side and the right hand side split of the assignment split by comment? I wanted to add an additional comment before the b
but that's blocked by #6866
Just pick anything (it's an autogenerated file) and recreate file, e.g. with |
Will review and merge today. I can also follow-up with new tests once I fix #6866. |
Okay, I had to make some changes to the PR to adapt to our parenthesis handling for patterns that changed a bit upstream (mostly, to ensure we handle the single-argument case correctly, like we do for call expressions). We also now handle comments before the arguments, like we do for call expressions. There are several comment cases that we're still getting wrong (valid syntax, but slightly incorrect placement), but that are really hard to fix without changing the AST. (Namely, we need an I'm going to update the AST, then do another pass on this node. |
... | ||
|
||
case A( | ||
b=# b |
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.
This is not quite right, but very tedious to fix without a node for the whole argument.
... | ||
|
||
case Point2D( | ||
# end of line |
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.
This is not quite right (it should be immediately after the (
), but very hard to fix without a node for the arguments.
Filed here: #6880. I'm on it. |
PR Check ResultsBenchmarkLinux
Windows
|
Summary
Closes #6642
Test Plan
cargo test