Commit ee76d24
committed
failed attempt at re-partitioning dangling comments
see #21410 (comment), but
the short summary is that `if` (and likely other) statement formatting code that
uses `maybe_parenthesize` checks if the condition has any leading or trailing
comments, so if we try to smuggle the comments in as dangling comments, it
thinks the expression won't break, so it doesn't add parentheses when formatting
a case like this:
```py
if (
not
# comment
a):
pass
```
and we end up with a syntax error:
```py
if
not a:
pass
```
There may be some other way around this, but this is why I'm giving up for now.
It really feels like we want another CommentPlacement variant or some kind of
dangling tag, like Micha mentioned when I met with him.1 parent d63b4b0 commit ee76d24
File tree
2 files changed
+43
-11
lines changed- crates/ruff_python_formatter/src
- comments
- expression
2 files changed
+43
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1865 | 1865 | | |
1866 | 1866 | | |
1867 | 1867 | | |
1868 | | - | |
| 1868 | + | |
| 1869 | + | |
1869 | 1870 | | |
| 1871 | + | |
1870 | 1872 | | |
1871 | 1873 | | |
1872 | 1874 | | |
| |||
Lines changed: 40 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| |||
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 28 | | |
33 | 29 | | |
34 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | 54 | | |
38 | 55 | | |
39 | 56 | | |
40 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
41 | 71 | | |
42 | 72 | | |
43 | 73 | | |
| |||
0 commit comments