Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RUF055 should categorize ) as a regex metacharacter #15316

Description

@dscorbett

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 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions