Rename dynamically-typed-expression to any-type (#2751)

This commit is contained in:
Martin Fischer 2023-02-11 01:02:31 +01:00 committed by GitHub
parent 6a87c99004
commit 0ec25d1514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 53 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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);

View file

@ -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 !(

View file

@ -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

View file

@ -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