Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIE800 fix introduces a syntax error for {**{},} #15997

Closed
dscorbett opened this issue Feb 6, 2025 · 0 comments · Fixed by #16008
Closed

PIE800 fix introduces a syntax error for {**{},} #15997

dscorbett opened this issue Feb 6, 2025 · 0 comments · Fixed by #16008
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dscorbett
Copy link

Description

The fix for unnecessary-spread (PIE800) in Ruff 0.9.4 introduces a syntax error when unpacking an empty dictionary that appears before a comma.

$ echo '{**{},}' | ruff --isolated check --select PIE800 - --diff

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `-`, the rule codes PIE800, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

@AlexWaygood AlexWaygood added bug Something isn't working fixes Related to suggested fixes for violations labels Feb 6, 2025
MichaReiser pushed a commit that referenced this issue Feb 7, 2025
…tionary is empty (`PIE800`) (#16008)

## Summary

Resolves #15997.

Ruff used to introduce syntax errors while fixing these cases, but no
longer will:

```python
{"a": [], **{},}
#         ^^^^ Removed, leaving two contiguous commas

{"a": [], **({})}
#         ^^^^^ Removed, leaving a stray closing parentheses
```

Previously, the function would take a shortcut if the unpacked
dictionary is empty; now, both cases are handled using the same logic
introduced in #15394. This change slightly modifies that logic to also
remove the first comma following the dictionary, if and only if it is
empty.

## Test Plan

`cargo nextest run` and `cargo insta test`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
2 participants