-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[ruff
] Ambiguous pattern passed to pytest.raises()
(RUF043
)
#14966
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF043 | 503 | 503 | 0 | 0 | 0 |
This is a really noisy rule. I checked some of the new violations; they all seem to be true positives. The rule currently don't have a fix. Should I add an unsafe "Wrap in |
crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs
Outdated
Show resolved
Hide resolved
This looks much better now, thank you! I feel like I'd prefer to have an example in the docs that uses a
And I think using an unescaped |
Done. Should we suggest an unsafe fix to go with it? |
crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_pytest_style/rules/raises.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT201.py
Outdated
Show resolved
Hide resolved
I'm not sure it's a good idea. Lots of the time it's pretty easy as a human to tell from looking at the string whether they intended the string to be a regex or a "plain" string. But I think it would be hard for Ruff to provide an accurate fix. E.g. here it's obvious that they did want the string to be a regex, so the correct fix would be to add the |
Too bad we can only suggest one fix per violation. If that weren't a thing, letting the user choose would be a very good solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be a PT
rule. We generally don't add a rule to a category corresponding to a pre-existing linter unless:
- the pre-existing linter also has the rule
- or the linter has been publicly declared to be deprecated/ummaintained
- or the linter has not seen any activity for >=2 years
Could you move this to the RUF
category? (The other option would be to open an issue with flake8-pytest-style asking if they would be willing to add the rule)
crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT201.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fantastic other than the comments I've just left. I think this is going to be a really useful rule!
flake8-pytest-style
] Ambiguous pattern passed to pytest.raises()
(PT201
)ruff
] Ambiguous pattern passed to pytest.raises()
(RUF043
)
@AlexWaygood Actually, it wasn't so fantastic. There was a major bug: The It was only because of your suggestion that I added more tests and thereby decided to also detect metasequences, which eventually lead to the discover of the bug. Thanks a lot! |
crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/pytest_raises_ambiguous_pattern.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Summary
Resolves #13705.
Test Plan
cargo nextest run
andcargo insta test
.