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

RUF055 should categorize ) as a regex metacharacter #15316

Closed
dscorbett opened this issue Jan 7, 2025 · 0 comments · Fixed by #15318
Closed

RUF055 should categorize ) as a regex metacharacter #15316

dscorbett opened this issue Jan 7, 2025 · 0 comments · Fixed by #15318
Labels
bug Something isn't working

Comments

@dscorbett
Copy link

unnecessary-regular-expression (RUF055) treats ) as a normal character that needs no escaping, but it is actually a metacharacter. This leads to false positives and fixes that change program behavior.

$ cat ruf055.py
import re
print(re.split(r")", "a)b"))

$ python ruf055.py 2>&1 | tail -n 1
re.error: unbalanced parenthesis at position 0

$ ruff check --isolated --preview --select RUF055 ruf055.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf055.py
import re
print("a)b".split(")"))

$ python ruf055.py
['a', 'b']

The current behavior was inspired by this review comment, but that comment only applies to ] and }, not ).

@MichaReiser MichaReiser added the bug Something isn't working label Jan 7, 2025
charliermarsh pushed a commit that referenced this issue Jan 7, 2025
)

## Summary

Resolves #15316.

## 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants