Avoid hard line break after dangling open-parenthesis comments (#6380)

## Summary

Given:

```python
[  # comment
    first,
    second,
    third
]  # another comment
```

We were adding a hard line break as part of the formatting of `#
comment`, which led to the following formatting:

```python
[first, second, third]  # comment
  # another comment
```

Closes https://github.com/astral-sh/ruff/issues/6367.
This commit is contained in:
Charlie Marsh 2023-08-07 10:15:32 -04:00 committed by GitHub
parent 63692b3798
commit b763973357
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 18 deletions

View file

@ -33,18 +33,19 @@ print( "111" ) # type: ignore
```diff
--- Black
+++ Ruff
@@ -1,10 +1,8 @@
@@ -1,12 +1,6 @@
# This is a regression test. Issue #3737
-a = ( # type: ignore
+a = int( # type: ignore # type: ignore
int( # type: ignore
- int( # type: ignore
- int( # type: ignore
- int(6) # type: ignore
- )
+ int(6) # type: ignore
)
)
- )
-)
+a = int(int(int(6))) # type: ignore # type: ignore # type: ignore # type: ignore
b = int(6)
```
@ -53,11 +54,7 @@ print( "111" ) # type: ignore
```py
# This is a regression test. Issue #3737
a = int( # type: ignore # type: ignore
int( # type: ignore
int(6) # type: ignore
)
)
a = int(int(int(6))) # type: ignore # type: ignore # type: ignore # type: ignore
b = int(6)

View file

@ -50,6 +50,12 @@ c1 = [ # trailing open bracket
[ # end-of-line comment
1
]
[ # inner comment
first,
second,
third
] # outer comment
```
## Output
@ -94,6 +100,8 @@ c1 = [ # trailing open bracket
]
[1] # end-of-line comment
[first, second, third] # inner comment # outer comment
```