Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 29, 2024
1 parent da36730 commit dca83a3
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 58 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::NonAsciiImportName) {
pylint::rules::non_ascii_module_import(checker, alias);
}
// TODO: remove once A004 is stable
// TODO(charlie): Remove when stabilizing A004.
if let Some(asname) = &alias.asname {
if checker.settings.preview.is_disabled()
&& checker.enabled(Rule::BuiltinVariableShadowing)
Expand Down Expand Up @@ -923,7 +923,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
));
}
} else {
// TODO: remove once A004 is stable
// TODO(charlie): Remove when stabilizing A004.
if let Some(asname) = &alias.asname {
if checker.settings.preview.is_disabled()
&& checker.enabled(Rule::BuiltinVariableShadowing)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ruff_python_ast::Parameter;

use ruff_diagnostics::Diagnostic;
use ruff_diagnostics::Violation;
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::Parameter;
use ruff_python_semantic::analyze::visibility::{is_overload, is_override};
use ruff_text_size::Ranged;

Expand All @@ -11,7 +10,7 @@ use crate::checkers::ast::Checker;
use super::super::helpers::shadows_builtin;

/// ## What it does
/// Checks for any function arguments that use the same name as a builtin.
/// Checks for function arguments that use the same names as builtins.
///
/// ## Why is this bad?
/// Reusing a builtin name for the name of an argument increases the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::checkers::ast::Checker;
use crate::rules::flake8_builtins::helpers::shadows_builtin;

/// ## What it does
/// Checks for any class attributes or methods that use the same name as a
/// builtin.
/// Checks for class attributes and methods that use the same names as
/// Python builtins.
///
/// ## Why is this bad?
/// Reusing a builtin name for the name of an attribute increases the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::checkers::ast::Checker;
use crate::rules::flake8_builtins::helpers::shadows_builtin;
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::Alias;

use crate::checkers::ast::Checker;
use crate::rules::flake8_builtins::helpers::shadows_builtin;

/// ## What it does
/// Checks for any import statement that use the same name as a builtin.
/// Checks for imports that use the same names as builtins.
///
/// ## Why is this bad?
/// Reusing a builtin name for the name of an import increases the
/// difficulty of reading and maintaining the code, and can cause
/// non-obvious errors, as readers may mistake the variable for the
/// builtin and vice versa.
/// Reusing a builtin for the name of an import increases the difficulty
/// of reading and maintaining the code, and can cause non-obvious errors,
/// as readers may mistake the variable for the builtin and vice versa.
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
Expand All @@ -27,7 +27,7 @@ impl Violation for BuiltinImportShadowing {
#[derive_message_formats]
fn message(&self) -> String {
let BuiltinImportShadowing { name } = self;
format!("Import `{name}` is shadowing Python builtin")
format!("Import `{name}` is shadowing a Python builtin")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::ExprLambda;
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::rules::flake8_builtins::helpers::shadows_builtin;

/// ## What it does
/// Checks for any lambda argument that use the same name as a builtin.
/// Checks for lambda arguments that use the same names as Python builtins.
///
/// ## Why is this bad?
/// Reusing a builtin name for the name of a lambda argument increases the
Expand All @@ -28,7 +29,7 @@ impl Violation for BuiltinLambdaArgumentShadowing {
#[derive_message_formats]
fn message(&self) -> String {
let BuiltinLambdaArgumentShadowing { name } = self;
format!("Lambda argument `{name}` is shadowing Python builtin")
format!("Lambda argument `{name}` is shadowing a Python builtin")
}
}

Expand All @@ -48,7 +49,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &mut Checker, lambda: &
BuiltinLambdaArgumentShadowing {
name: name.to_string(),
},
name.range,
name.range(),
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ruff_text_size::TextRange;
use crate::settings::types::PythonVersion;

/// ## What it does
/// Checks for any module that use the same name as a builtin module.
/// Checks for modules that use the same names as Python builtin modules.
///
/// ## Why is this bad?
/// Reusing a builtin module name for the name of a module increases the
Expand All @@ -31,7 +31,7 @@ impl Violation for BuiltinModuleShadowing {
#[derive_message_formats]
fn message(&self) -> String {
let BuiltinModuleShadowing { name } = self;
format!("Module `{name}` is shadowing Python builtin module")
format!("Module `{name}` is shadowing a Python builtin module")
}
}

Expand All @@ -51,12 +51,10 @@ pub(crate) fn builtin_module_shadowing(

if let Some(package) = package {
let module_name = if is_module_file(path) {
package.file_name()
package.file_name().unwrap().to_string_lossy()
} else {
path.file_stem()
}
.unwrap()
.to_string_lossy();
path.file_stem().unwrap().to_string_lossy()
};

if is_known_standard_library(target_version.minor(), &module_name)
&& allowed_modules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use ruff_text_size::TextRange;

use ruff_diagnostics::Diagnostic;
use ruff_diagnostics::Violation;
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::TextRange;

use crate::checkers::ast::Checker;
use crate::rules::flake8_builtins::helpers::shadows_builtin;

/// ## What it does
/// Checks for variable (and function) assignments that use the same name
/// as a builtin.
/// Checks for variable (and function) assignments that use the same names
/// as builtins.
///
/// ## Why is this bad?
/// Reusing a builtin name for the name of a variable increases the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
A004.py:1:16: A004 Import `sum` is shadowing Python builtin
A004.py:1:16: A004 Import `sum` is shadowing a Python builtin
|
1 | import some as sum
| ^^^ A004
2 | import float
3 | from some import other as int
|

A004.py:2:8: A004 Import `float` is shadowing Python builtin
A004.py:2:8: A004 Import `float` is shadowing a Python builtin
|
1 | import some as sum
2 | import float
Expand All @@ -18,7 +18,7 @@ A004.py:2:8: A004 Import `float` is shadowing Python builtin
4 | from some import input, exec
|

A004.py:3:27: A004 Import `int` is shadowing Python builtin
A004.py:3:27: A004 Import `int` is shadowing a Python builtin
|
1 | import some as sum
2 | import float
Expand All @@ -28,7 +28,7 @@ A004.py:3:27: A004 Import `int` is shadowing Python builtin
5 | from directory import new as dir
|

A004.py:4:18: A004 Import `input` is shadowing Python builtin
A004.py:4:18: A004 Import `input` is shadowing a Python builtin
|
2 | import float
3 | from some import other as int
Expand All @@ -37,7 +37,7 @@ A004.py:4:18: A004 Import `input` is shadowing Python builtin
5 | from directory import new as dir
|

A004.py:4:25: A004 Import `exec` is shadowing Python builtin
A004.py:4:25: A004 Import `exec` is shadowing a Python builtin
|
2 | import float
3 | from some import other as int
Expand All @@ -46,7 +46,7 @@ A004.py:4:25: A004 Import `exec` is shadowing Python builtin
5 | from directory import new as dir
|

A004.py:5:30: A004 Import `dir` is shadowing Python builtin
A004.py:5:30: A004 Import `dir` is shadowing a Python builtin
|
3 | from some import other as int
4 | from some import input, exec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
A004.py:1:16: A004 Import `sum` is shadowing Python builtin
A004.py:1:16: A004 Import `sum` is shadowing a Python builtin
|
1 | import some as sum
| ^^^ A004
2 | import float
3 | from some import other as int
|

A004.py:2:8: A004 Import `float` is shadowing Python builtin
A004.py:2:8: A004 Import `float` is shadowing a Python builtin
|
1 | import some as sum
2 | import float
Expand All @@ -18,7 +18,7 @@ A004.py:2:8: A004 Import `float` is shadowing Python builtin
4 | from some import input, exec
|

A004.py:3:27: A004 Import `int` is shadowing Python builtin
A004.py:3:27: A004 Import `int` is shadowing a Python builtin
|
1 | import some as sum
2 | import float
Expand All @@ -28,7 +28,7 @@ A004.py:3:27: A004 Import `int` is shadowing Python builtin
5 | from directory import new as dir
|

A004.py:4:18: A004 Import `input` is shadowing Python builtin
A004.py:4:18: A004 Import `input` is shadowing a Python builtin
|
2 | import float
3 | from some import other as int
Expand All @@ -37,7 +37,7 @@ A004.py:4:18: A004 Import `input` is shadowing Python builtin
5 | from directory import new as dir
|

A004.py:4:25: A004 Import `exec` is shadowing Python builtin
A004.py:4:25: A004 Import `exec` is shadowing a Python builtin
|
2 | import float
3 | from some import other as int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
__init__.py:1:1: A005 Module `logging` is shadowing Python builtin module
__init__.py:1:1: A005 Module `logging` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
bisect.py:1:1: A005 Module `bisect` is shadowing Python builtin module
bisect.py:1:1: A005 Module `bisect` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
bisect.py:1:1: A005 Module `bisect` is shadowing Python builtin module
bisect.py:1:1: A005 Module `bisect` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
xml.py:1:1: A005 Module `xml` is shadowing Python builtin module
xml.py:1:1: A005 Module `xml` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
__init__.py:1:1: A005 Module `string` is shadowing Python builtin module
__init__.py:1:1: A005 Module `string` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
__init__.py:1:1: A005 Module `string` is shadowing Python builtin module
__init__.py:1:1: A005 Module `string` is shadowing a Python builtin module
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---
A006.py:1:8: A006 Lambda argument `print` is shadowing Python builtin
A006.py:1:8: A006 Lambda argument `print` is shadowing a Python builtin
|
1 | lambda print, copyright: print
| ^^^^^ A006
2 | lambda x, float, y: x + y
3 | lambda min, max: min
|

A006.py:1:15: A006 Lambda argument `copyright` is shadowing Python builtin
A006.py:1:15: A006 Lambda argument `copyright` is shadowing a Python builtin
|
1 | lambda print, copyright: print
| ^^^^^^^^^ A006
2 | lambda x, float, y: x + y
3 | lambda min, max: min
|

A006.py:2:11: A006 Lambda argument `float` is shadowing Python builtin
A006.py:2:11: A006 Lambda argument `float` is shadowing a Python builtin
|
1 | lambda print, copyright: print
2 | lambda x, float, y: x + y
Expand All @@ -26,7 +26,7 @@ A006.py:2:11: A006 Lambda argument `float` is shadowing Python builtin
4 | lambda id: id
|

A006.py:3:8: A006 Lambda argument `min` is shadowing Python builtin
A006.py:3:8: A006 Lambda argument `min` is shadowing a Python builtin
|
1 | lambda print, copyright: print
2 | lambda x, float, y: x + y
Expand All @@ -36,7 +36,7 @@ A006.py:3:8: A006 Lambda argument `min` is shadowing Python builtin
5 | lambda dir: dir
|

A006.py:3:13: A006 Lambda argument `max` is shadowing Python builtin
A006.py:3:13: A006 Lambda argument `max` is shadowing a Python builtin
|
1 | lambda print, copyright: print
2 | lambda x, float, y: x + y
Expand All @@ -46,7 +46,7 @@ A006.py:3:13: A006 Lambda argument `max` is shadowing Python builtin
5 | lambda dir: dir
|

A006.py:4:8: A006 Lambda argument `id` is shadowing Python builtin
A006.py:4:8: A006 Lambda argument `id` is shadowing a Python builtin
|
2 | lambda x, float, y: x + y
3 | lambda min, max: min
Expand All @@ -55,7 +55,7 @@ A006.py:4:8: A006 Lambda argument `id` is shadowing Python builtin
5 | lambda dir: dir
|

A006.py:5:8: A006 Lambda argument `dir` is shadowing Python builtin
A006.py:5:8: A006 Lambda argument `dir` is shadowing a Python builtin
|
3 | lambda min, max: min
4 | lambda id: id
Expand Down
Loading

0 comments on commit dca83a3

Please sign in to comment.