mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
Fix bracket spacing for single-element tuples in f-string expressions (#15537)
This commit is contained in:
parent
556116ee76
commit
9ed67ba33e
3 changed files with 64 additions and 11 deletions
|
@ -724,6 +724,14 @@ print(f"{ {1: 2}.keys() }")
|
|||
print(f"{({1, 2, 3}) - ({2})}")
|
||||
print(f"{1, 2, {3} }")
|
||||
print(f"{(1, 2, {3})}")
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/15535
|
||||
print(f"{ {}, }") # A single item tuple gets parenthesized
|
||||
print(f"{ {}.values(), }")
|
||||
print(f"{ {}, 1 }") # A tuple with multiple elements doesn't get parenthesized
|
||||
print(f"{ # Tuple with multiple elements that doesn't fit on a single line gets parenthesized
|
||||
{}, 1,
|
||||
}")
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
@ -1506,6 +1514,19 @@ print(f"{ {1: 2}.keys() }")
|
|||
print(f"{({1, 2, 3}) - ({2})}")
|
||||
print(f"{1, 2, {3}}")
|
||||
print(f"{(1, 2, {3})}")
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/15535
|
||||
print(f"{({},)}") # A single item tuple gets parenthesized
|
||||
print(f"{({}.values(),)}")
|
||||
print(f"{ {}, 1 }") # A tuple with multiple elements doesn't get parenthesized
|
||||
print(
|
||||
f"{ # Tuple with multiple elements that doesn't fit on a single line gets parenthesized
|
||||
(
|
||||
{},
|
||||
1,
|
||||
)
|
||||
}"
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
@ -2288,4 +2309,17 @@ print(f"{ {1: 2}.keys() }")
|
|||
print(f"{({1, 2, 3}) - ({2})}")
|
||||
print(f"{1, 2, {3}}")
|
||||
print(f"{(1, 2, {3})}")
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/15535
|
||||
print(f"{({},)}") # A single item tuple gets parenthesized
|
||||
print(f"{({}.values(),)}")
|
||||
print(f"{ {}, 1 }") # A tuple with multiple elements doesn't get parenthesized
|
||||
print(
|
||||
f"{ # Tuple with multiple elements that doesn't fit on a single line gets parenthesized
|
||||
(
|
||||
{},
|
||||
1,
|
||||
)
|
||||
}"
|
||||
)
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue