mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Rename dynamically-typed-expression to any-type (#2751)
This commit is contained in:
parent
6a87c99004
commit
0ec25d1514
8 changed files with 34 additions and 53 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<F>(
|
|||
{
|
||||
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 !(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# dynamically-typed-expression (ANN401)
|
||||
# any-type (ANN401)
|
||||
|
||||
Derived from the **flake8-annotations** linter.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue