mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 23:27:38 +00:00
Use optional parentheses for tuples in return statements (#6875)
This commit is contained in:
parent
19ccf1d073
commit
adb48692d6
5 changed files with 112 additions and 33 deletions
|
@ -252,33 +252,23 @@ self.assertEqual(
|
|||
|
||||
def test():
|
||||
return (
|
||||
(
|
||||
"((TIME_TO_SEC(%(lhs)s) * 1000000 + MICROSECOND(%(lhs)s)) -"
|
||||
" (TIME_TO_SEC(%(rhs)s) * 1000000 + MICROSECOND(%(rhs)s)))"
|
||||
) % {"lhs": lhs_sql, "rhs": rhs_sql},
|
||||
tuple(lhs_params) * 2 + tuple(rhs_params) * 2,
|
||||
)
|
||||
"((TIME_TO_SEC(%(lhs)s) * 1000000 + MICROSECOND(%(lhs)s)) -"
|
||||
" (TIME_TO_SEC(%(rhs)s) * 1000000 + MICROSECOND(%(rhs)s)))"
|
||||
) % {"lhs": lhs_sql, "rhs": rhs_sql}, tuple(lhs_params) * 2 + tuple(rhs_params) * 2
|
||||
|
||||
|
||||
def test2():
|
||||
return (
|
||||
"RETURNING %s INTO %s"
|
||||
% (
|
||||
", ".join(field_names),
|
||||
", ".join(["%s"] * len(params)),
|
||||
),
|
||||
tuple(params),
|
||||
)
|
||||
return "RETURNING %s INTO %s" % (
|
||||
", ".join(field_names),
|
||||
", ".join(["%s"] * len(params)),
|
||||
), tuple(params)
|
||||
|
||||
|
||||
def test3():
|
||||
return (
|
||||
(
|
||||
"(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
|
||||
"THEN JSON_TYPE(%s, %%s) ELSE JSON_EXTRACT(%s, %%s) END)"
|
||||
) % (lhs, datatype_values, lhs, lhs),
|
||||
(tuple(params) + (json_path,)) * 3,
|
||||
)
|
||||
"(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
|
||||
"THEN JSON_TYPE(%s, %%s) ELSE JSON_EXTRACT(%s, %%s) END)"
|
||||
) % (lhs, datatype_values, lhs, lhs), (tuple(params) + (json_path,)) * 3
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/return.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
|
||||
return len(self.nodeseeeeeeeee), sum(
|
||||
len(node.parents) for node in self.node_map.values()
|
||||
)
|
||||
|
||||
|
||||
return len(self.nodeseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee), sum(
|
||||
len(node.parents) for node in self.node_map.values()
|
||||
)
|
||||
|
||||
|
||||
return (
|
||||
len(self.nodeseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee), sum(
|
||||
len(node.parents) for node in self.node_map.values()
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
return len(self.nodeseeeeeeeee), sum(
|
||||
len(node.parents) for node in self.node_map.values()
|
||||
)
|
||||
|
||||
|
||||
return len(
|
||||
self.nodeseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||
), sum(len(node.parents) for node in self.node_map.values())
|
||||
|
||||
|
||||
return (
|
||||
len(self.nodeseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee),
|
||||
sum(len(node.parents) for node in self.node_map.values()),
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue