-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingformatterRelated to the formatterRelated to the formatter
Description
Summary
Describe the bug
When using a tuple of exceptions in an except block with the unpacking syntax, Ruff’s formatter produces invalid Python code. The formatting chain progressively corrupts the syntax.
Steps to reproduce
- Start with this code:
import orjson
JSON_DECODE_EXCEPTIONS = (orjson.JSONDecodeError,)
def fibonacci(n):
"""Compute the nth number in the Fibonacci sequence."""
try:
return 1
except (*JSON_DECODE_EXCEPTIONS, ValueError):
return []- Apply Ruff formatting. It first produces:
import orjson
JSON_DECODE_EXCEPTIONS = (orjson.JSONDecodeError,)
def fibonacci(n):
"""Compute the nth number in the Fibonacci sequence."""
try:
return 1
except *JSON_DECODE_EXCEPTIONS, ValueError:
return []- Applying Ruff again, it produces invalid syntax:
import orjson
JSON_DECODE_EXCEPTIONS = (orjson.JSONDecode_EXCEPTIONS,)
def fibonacci(n):
"""Compute the nth number in the Fibonacci sequence."""
try:
return 1
except* JSON_DECODE_EXCEPTIONS, ValueError:
return []Playground links
Initial formatting: https://play.ruff.rs/671ad30c-c884-4fa6-ab21-8c8f1a5f494f
Second formatting: https://play.ruff.rs/e1fe4e28-8ecb-4af9-9792-22753c51ddcb
See: home-assistant/core#162356
Version
ruff 0.15.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingformatterRelated to the formatterRelated to the formatter