diff --git a/README.md b/README.md index 7ed31aa9a4..8189a35e70 100644 --- a/README.md +++ b/README.md @@ -910,7 +910,7 @@ For more, see [flake8-annotations](https://pypi.org/project/flake8-annotations/) | ANN204 | [missing-return-type-special-method](https://github.com/charliermarsh/ruff/blob/main/docs/rules/missing-return-type-special-method.md) | Missing return type annotation for special method `{name}` | 🛠 | | ANN205 | [missing-return-type-static-method](https://github.com/charliermarsh/ruff/blob/main/docs/rules/missing-return-type-static-method.md) | Missing return type annotation for staticmethod `{name}` | | | ANN206 | [missing-return-type-class-method](https://github.com/charliermarsh/ruff/blob/main/docs/rules/missing-return-type-class-method.md) | Missing return type annotation for classmethod `{name}` | | -| ANN401 | [dynamically-typed-expression](https://github.com/charliermarsh/ruff/blob/main/docs/rules/dynamically-typed-expression.md) | Dynamically typed expressions (typing.Any) are disallowed in `{name}` | | +| ANN401 | [any-type](https://github.com/charliermarsh/ruff/blob/main/docs/rules/any-type.md) | Dynamically typed expressions (typing.Any) are disallowed in `{name}` | | ### flake8-bandit (S) diff --git a/crates/ruff/src/checkers/ast.rs b/crates/ruff/src/checkers/ast.rs index 45bda397ae..dc6541af96 100644 --- a/crates/ruff/src/checkers/ast.rs +++ b/crates/ruff/src/checkers/ast.rs @@ -5033,10 +5033,7 @@ impl<'a> Checker<'a> { .settings .rules .enabled(&Rule::MissingReturnTypeClassMethod) - || self - .settings - .rules - .enabled(&Rule::DynamicallyTypedExpression); + || self.settings.rules.enabled(&Rule::AnyType); let enforce_docstrings = self.settings.rules.enabled(&Rule::PublicModule) || self.settings.rules.enabled(&Rule::PublicClass) || self.settings.rules.enabled(&Rule::PublicMethod) diff --git a/crates/ruff/src/registry.rs b/crates/ruff/src/registry.rs index 97591bdcf6..0dc874533a 100644 --- a/crates/ruff/src/registry.rs +++ b/crates/ruff/src/registry.rs @@ -239,7 +239,7 @@ ruff_macros::define_rule_mapping!( ANN204 => rules::flake8_annotations::rules::MissingReturnTypeSpecialMethod, ANN205 => rules::flake8_annotations::rules::MissingReturnTypeStaticMethod, ANN206 => rules::flake8_annotations::rules::MissingReturnTypeClassMethod, - ANN401 => rules::flake8_annotations::rules::DynamicallyTypedExpression, + ANN401 => rules::flake8_annotations::rules::AnyType, // flake8-2020 YTT101 => rules::flake8_2020::rules::SysVersionSlice3Referenced, YTT102 => rules::flake8_2020::rules::SysVersion2Referenced, diff --git a/crates/ruff/src/rules/flake8_annotations/mod.rs b/crates/ruff/src/rules/flake8_annotations/mod.rs index 2517b6ed1c..a6ebf9f3f5 100644 --- a/crates/ruff/src/rules/flake8_annotations/mod.rs +++ b/crates/ruff/src/rules/flake8_annotations/mod.rs @@ -31,7 +31,7 @@ mod tests { Rule::MissingReturnTypeSpecialMethod, Rule::MissingReturnTypeStaticMethod, Rule::MissingReturnTypeClassMethod, - Rule::DynamicallyTypedExpression, + Rule::AnyType, ]) }, )?; @@ -59,7 +59,7 @@ mod tests { Rule::MissingReturnTypeSpecialMethod, Rule::MissingReturnTypeStaticMethod, Rule::MissingReturnTypeClassMethod, - Rule::DynamicallyTypedExpression, + Rule::AnyType, ]) }, )?; @@ -131,7 +131,7 @@ mod tests { Rule::MissingReturnTypeSpecialMethod, Rule::MissingReturnTypeStaticMethod, Rule::MissingReturnTypeClassMethod, - Rule::DynamicallyTypedExpression, + Rule::AnyType, ]) }, )?; @@ -148,7 +148,7 @@ mod tests { allow_star_arg_any: true, ..Default::default() }, - ..Settings::for_rules(vec![Rule::DynamicallyTypedExpression]) + ..Settings::for_rules(vec![Rule::AnyType]) }, )?; assert_yaml_snapshot!(diagnostics); diff --git a/crates/ruff/src/rules/flake8_annotations/rules.rs b/crates/ruff/src/rules/flake8_annotations/rules.rs index 7737a7ca4f..db848fc7b8 100644 --- a/crates/ruff/src/rules/flake8_annotations/rules.rs +++ b/crates/ruff/src/rules/flake8_annotations/rules.rs @@ -401,14 +401,14 @@ define_violation!( /// * [PEP 484](https://www.python.org/dev/peps/pep-0484/#the-any-type) /// * [`typing.Any`](https://docs.python.org/3/library/typing.html#typing.Any) /// * [Mypy: The Any type](https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-any-type) - pub struct DynamicallyTypedExpression { + pub struct AnyType { pub name: String, } ); -impl Violation for DynamicallyTypedExpression { +impl Violation for AnyType { #[derive_message_formats] fn message(&self) -> String { - let DynamicallyTypedExpression { name } = self; + let AnyType { name } = self; format!("Dynamically typed expressions (typing.Any) are disallowed in `{name}`") } } @@ -443,7 +443,7 @@ fn check_dynamically_typed( { if checker.match_typing_expr(annotation, "Any") { diagnostics.push(Diagnostic::new( - DynamicallyTypedExpression { name: func() }, + AnyType { name: func() }, Range::from_located(annotation), )); }; @@ -489,11 +489,7 @@ pub fn definition( // ANN401 for dynamically typed arguments if let Some(annotation) = &arg.node.annotation { has_any_typed_arg = true; - if checker - .settings - .rules - .enabled(&Rule::DynamicallyTypedExpression) - { + if checker.settings.rules.enabled(&Rule::AnyType) { check_dynamically_typed( checker, annotation, @@ -526,11 +522,7 @@ pub fn definition( if let Some(expr) = &arg.node.annotation { has_any_typed_arg = true; if !checker.settings.flake8_annotations.allow_star_arg_any { - if checker - .settings - .rules - .enabled(&Rule::DynamicallyTypedExpression) - { + if checker.settings.rules.enabled(&Rule::AnyType) { let name = &arg.node.arg; check_dynamically_typed( checker, @@ -561,11 +553,7 @@ pub fn definition( if let Some(expr) = &arg.node.annotation { has_any_typed_arg = true; if !checker.settings.flake8_annotations.allow_star_arg_any { - if checker - .settings - .rules - .enabled(&Rule::DynamicallyTypedExpression) - { + if checker.settings.rules.enabled(&Rule::AnyType) { let name = &arg.node.arg; check_dynamically_typed( checker, @@ -623,11 +611,7 @@ pub fn definition( // ANN201, ANN202, ANN401 if let Some(expr) = &returns { has_typed_return = true; - if checker - .settings - .rules - .enabled(&Rule::DynamicallyTypedExpression) - { + if checker.settings.rules.enabled(&Rule::AnyType) { check_dynamically_typed(checker, expr, || name.to_string(), &mut diagnostics); } } else if !( diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap index 3414cc77f8..374681e49a 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap @@ -1,9 +1,9 @@ --- -source: src/rules/flake8_annotations/mod.rs +source: crates/ruff/src/rules/flake8_annotations/mod.rs expression: diagnostics --- - kind: - DynamicallyTypedExpression: + AnyType: name: a location: row: 10 @@ -14,7 +14,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: foo location: row: 15 @@ -25,7 +25,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: a location: row: 40 @@ -36,7 +36,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: foo_method location: row: 44 diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap index 69151767f0..d53e11d647 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap @@ -1,5 +1,5 @@ --- -source: src/rules/flake8_annotations/mod.rs +source: crates/ruff/src/rules/flake8_annotations/mod.rs expression: diagnostics --- - kind: @@ -91,7 +91,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: a location: row: 44 @@ -102,7 +102,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: foo location: row: 49 @@ -113,7 +113,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "*args" location: row: 54 @@ -124,7 +124,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "**kwargs" location: row: 54 @@ -135,7 +135,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "*args" location: row: 59 @@ -146,7 +146,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "**kwargs" location: row: 64 @@ -168,7 +168,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: a location: row: 78 @@ -179,7 +179,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: foo location: row: 82 @@ -190,7 +190,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "*params" location: row: 86 @@ -201,7 +201,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "**options" location: row: 86 @@ -212,7 +212,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "*params" location: row: 90 @@ -223,7 +223,7 @@ expression: diagnostics fix: ~ parent: ~ - kind: - DynamicallyTypedExpression: + AnyType: name: "**options" location: row: 94 diff --git a/docs/rules/dynamically-typed-expression.md b/docs/rules/any-type.md similarity index 91% rename from docs/rules/dynamically-typed-expression.md rename to docs/rules/any-type.md index e4706df1ee..abd3a1e1dd 100644 --- a/docs/rules/dynamically-typed-expression.md +++ b/docs/rules/any-type.md @@ -1,4 +1,4 @@ -# dynamically-typed-expression (ANN401) +# any-type (ANN401) Derived from the **flake8-annotations** linter.