mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
Stabilize pytest-raises-ambiguous-pattern (RUF043) (#20253)
This one has been a bit contentious in the past. It usually uncovers ~700 ecosystem hits. See: - https://github.com/astral-sh/ruff/pull/16657 - https://github.com/astral-sh/ruff/issues/16690 But I think there's consensus that it's okay to merge as-is. We'd love an autofix since it's so common, but we can't reliably tell what a user meant. The pattern is ambiguous after all 😆 This is the first rule that actually needed its test case relocated, but the docs looked good.
This commit is contained in:
parent
bb4c51afb2
commit
1bbb553d6f
4 changed files with 6 additions and 5 deletions
|
|
@ -1032,7 +1032,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Ruff, "039") => (RuleGroup::Preview, rules::ruff::rules::UnrawRePattern),
|
||||
(Ruff, "040") => (RuleGroup::Stable, rules::ruff::rules::InvalidAssertMessageLiteralArgument),
|
||||
(Ruff, "041") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryNestedLiteral),
|
||||
(Ruff, "043") => (RuleGroup::Preview, rules::ruff::rules::PytestRaisesAmbiguousPattern),
|
||||
(Ruff, "043") => (RuleGroup::Stable, rules::ruff::rules::PytestRaisesAmbiguousPattern),
|
||||
(Ruff, "045") => (RuleGroup::Preview, rules::ruff::rules::ImplicitClassVarInDataclass),
|
||||
(Ruff, "046") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryCastToInt),
|
||||
(Ruff, "047") => (RuleGroup::Preview, rules::ruff::rules::NeedlessElse),
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ mod tests {
|
|||
#[test_case(Rule::InvalidAssertMessageLiteralArgument, Path::new("RUF040.py"))]
|
||||
#[test_case(Rule::UnnecessaryNestedLiteral, Path::new("RUF041.py"))]
|
||||
#[test_case(Rule::UnnecessaryNestedLiteral, Path::new("RUF041.pyi"))]
|
||||
#[test_case(Rule::PytestRaisesAmbiguousPattern, Path::new("RUF043.py"))]
|
||||
#[test_case(Rule::UnnecessaryCastToInt, Path::new("RUF046.py"))]
|
||||
#[test_case(Rule::UnnecessaryCastToInt, Path::new("RUF046_CR.py"))]
|
||||
#[test_case(Rule::UnnecessaryCastToInt, Path::new("RUF046_LF.py"))]
|
||||
|
|
@ -535,7 +536,6 @@ mod tests {
|
|||
#[test_case(Rule::UnnecessaryRegularExpression, Path::new("RUF055_1.py"))]
|
||||
#[test_case(Rule::UnnecessaryRegularExpression, Path::new("RUF055_2.py"))]
|
||||
#[test_case(Rule::UnnecessaryRegularExpression, Path::new("RUF055_3.py"))]
|
||||
#[test_case(Rule::PytestRaisesAmbiguousPattern, Path::new("RUF043.py"))]
|
||||
#[test_case(Rule::IndentedFormFeed, Path::new("RUF054.py"))]
|
||||
#[test_case(Rule::ImplicitClassVarInDataclass, Path::new("RUF045.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ use crate::rules::flake8_pytest_style::rules::is_pytest_raises;
|
|||
/// do_thing_that_raises()
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// If the pattern is intended to be a regular expression, use a raw string to signal this
|
||||
/// intention:
|
||||
///
|
||||
/// ```python
|
||||
/// import pytest
|
||||
|
|
@ -37,7 +38,7 @@ use crate::rules::flake8_pytest_style::rules::is_pytest_raises;
|
|||
/// do_thing_that_raises()
|
||||
/// ```
|
||||
///
|
||||
/// Alternatively:
|
||||
/// Alternatively, escape any regex metacharacters with `re.escape`:
|
||||
///
|
||||
/// ```python
|
||||
/// import pytest
|
||||
|
|
@ -48,7 +49,7 @@ use crate::rules::flake8_pytest_style::rules::is_pytest_raises;
|
|||
/// do_thing_that_raises()
|
||||
/// ```
|
||||
///
|
||||
/// or:
|
||||
/// or directly with backslashes:
|
||||
///
|
||||
/// ```python
|
||||
/// import pytest
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue