mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00

## Summary This formats call expressions with magic trailing comma and parentheses behaviour but without call chaining ## Test Plan Lots of new test fixtures, including some that don't work yet
189 lines
5.5 KiB
Text
189 lines
5.5 KiB
Text
---
|
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py
|
|
---
|
|
## Input
|
|
|
|
```py
|
|
# The percent-percent comments are Spyder IDE cells.
|
|
|
|
|
|
# %%
|
|
def func():
|
|
x = """
|
|
a really long string
|
|
"""
|
|
lcomp3 = [
|
|
# This one is actually too long to fit in a single line.
|
|
element.split("\n", 1)[0]
|
|
# yup
|
|
for element in collection.select_elements()
|
|
# right
|
|
if element is not None
|
|
]
|
|
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
|
if isinstance(exc_value, MultiError):
|
|
embedded = []
|
|
for exc in exc_value.exceptions:
|
|
if exc not in _seen:
|
|
embedded.append(
|
|
# This should be left alone (before)
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
)
|
|
# This should be left alone (after)
|
|
)
|
|
|
|
# everything is fine if the expression isn't nested
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
)
|
|
|
|
|
|
# %%
|
|
```
|
|
|
|
## Black Differences
|
|
|
|
```diff
|
|
--- Black
|
|
+++ Ruff
|
|
@@ -6,14 +6,7 @@
|
|
x = """
|
|
a really long string
|
|
"""
|
|
- lcomp3 = [
|
|
- # This one is actually too long to fit in a single line.
|
|
- element.split("\n", 1)[0]
|
|
- # yup
|
|
- for element in collection.select_elements()
|
|
- # right
|
|
- if element is not None
|
|
- ]
|
|
+ lcomp3 = [i for i in []]
|
|
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
|
if isinstance(exc_value, MultiError):
|
|
embedded = []
|
|
@@ -29,7 +22,7 @@
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
- )
|
|
+ ),
|
|
# This should be left alone (after)
|
|
)
|
|
|
|
```
|
|
|
|
## Ruff Output
|
|
|
|
```py
|
|
# The percent-percent comments are Spyder IDE cells.
|
|
|
|
|
|
# %%
|
|
def func():
|
|
x = """
|
|
a really long string
|
|
"""
|
|
lcomp3 = [i for i in []]
|
|
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
|
if isinstance(exc_value, MultiError):
|
|
embedded = []
|
|
for exc in exc_value.exceptions:
|
|
if exc not in _seen:
|
|
embedded.append(
|
|
# This should be left alone (before)
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
),
|
|
# This should be left alone (after)
|
|
)
|
|
|
|
# everything is fine if the expression isn't nested
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
)
|
|
|
|
|
|
# %%
|
|
```
|
|
|
|
## Black Output
|
|
|
|
```py
|
|
# The percent-percent comments are Spyder IDE cells.
|
|
|
|
|
|
# %%
|
|
def func():
|
|
x = """
|
|
a really long string
|
|
"""
|
|
lcomp3 = [
|
|
# This one is actually too long to fit in a single line.
|
|
element.split("\n", 1)[0]
|
|
# yup
|
|
for element in collection.select_elements()
|
|
# right
|
|
if element is not None
|
|
]
|
|
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
|
if isinstance(exc_value, MultiError):
|
|
embedded = []
|
|
for exc in exc_value.exceptions:
|
|
if exc not in _seen:
|
|
embedded.append(
|
|
# This should be left alone (before)
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
)
|
|
# This should be left alone (after)
|
|
)
|
|
|
|
# everything is fine if the expression isn't nested
|
|
traceback.TracebackException.from_exception(
|
|
exc,
|
|
limit=limit,
|
|
lookup_lines=lookup_lines,
|
|
capture_locals=capture_locals,
|
|
# copy the set of _seen exceptions so that duplicates
|
|
# shared between sub-exceptions are not omitted
|
|
_seen=set(_seen),
|
|
)
|
|
|
|
|
|
# %%
|
|
```
|
|
|
|
|