ruff/crates/ruff_python_formatter/src/comments
Charlie Marsh 15b73bdb8a
Introduce AST nodes for PatternMatchClass arguments (#6881)
## Summary

This PR introduces two new AST nodes to improve the representation of
`PatternMatchClass`. As a reminder, `PatternMatchClass` looks like this:

```python
case Point2D(0, 0, x=1, y=2):
  ...
```

Historically, this was represented as a vector of patterns (for the `0,
0` portion) and parallel vectors of keyword names (for `x` and `y`) and
values (for `1` and `2`). This introduces a bunch of challenges for the
formatter, but importantly, it's also really different from how we
represent similar nodes, like arguments (`func(0, 0, x=1, y=2)`) or
parameters (`def func(x, y)`).

So, firstly, we now use a single node (`PatternArguments`) for the
entire parenthesized region, making it much more consistent with our
other nodes. So, above, `PatternArguments` would be `(0, 0, x=1, y=2)`.

Secondly, we now have a `PatternKeyword` node for `x=1` and `y=2`. This
is much more similar to the how `Keyword` is represented within
`Arguments` for call expressions.

Closes https://github.com/astral-sh/ruff/issues/6866.

Closes https://github.com/astral-sh/ruff/issues/6880.
2023-08-26 14:45:44 +00:00
..
snapshots Add general support for parenthesized comments on expressions (#6485) 2023-08-15 18:59:18 +00:00
debug.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
format.rs Fix formatting of comments between function and arguments (#6826) 2023-08-25 04:06:56 +00:00
map.rs Use single lookup for leading, dangling, and trailing comments (#6589) 2023-08-15 17:39:45 +02:00
mod.rs Rename Comments methods (#6649) 2023-08-18 06:37:01 +00:00
node_key.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
placement.rs Introduce AST nodes for PatternMatchClass arguments (#6881) 2023-08-26 14:45:44 +00:00
visitor.rs Preserve dangling f-string comments 2023-08-10 09:11:25 +02:00