-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
detect if a regex escape is needed in a pytest match statement #13705
Comments
@InSyncWithFoo was so kind to implement the rule and we looked through the ecosystem changes. After seeing the changes, I don't think we should add this rule to ruff. While it's true that the It makes me wonder if we could create ar ule that warns about |
Easier for escaped that don't need to be, much harder for not-escaped that should to be. Pytest matches can work with regex, so it would be very hard to figure out if a string that looks like a regex isn't and should be escaped. |
If you have a string passed to
Then I think it's reasonable to say that the string should either be a raw string (if it's meant to be a regex) or should be surrounded by |
Sounds good to me. This also goes well with |
And the reverse — if a string is surrounded by |
We already considered and rejected that check in #14746, as Micha stated above in #13705 (comment) I agree with his rationale. |
I suppose I can go ahead and implement the new rule then? A PR should be ready sometime later this week. |
Sometimes
re.escape
are needed in pytest formatch=...
arguments.Then the string is modified and the regex escape is no longer needed.
It would be great if ruff could detect this and remove the unneeded
re.escape
.M~WE:
The text was updated successfully, but these errors were encountered: