[ruff] Ambiguous pattern passed to pytest.raises() (RUF043)#14966
[ruff] Ambiguous pattern passed to pytest.raises() (RUF043)#14966AlexWaygood merged 10 commits intoastral-sh:mainfrom
ruff] Ambiguous pattern passed to pytest.raises() (RUF043)#14966Conversation
|
| 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. |
AlexWaygood
left a comment
There was a problem hiding this comment.
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
AlexWaygood
left a comment
There was a problem hiding this comment.
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! |
Summary
Resolves #13705.
Test Plan
cargo nextest runandcargo insta test.