Skip to content

Commit 5d56c2e

Browse files
authored
[flake8-builtins] Ignore variables matching module attribute names (A001) (#16454)
This PR (partially) addresses issue #16373
1 parent c80678a commit 5d56c2e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_builtins/A001.py

+10
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ class slice:
2828
pass
2929

3030
[0 for sum in ()]
31+
32+
33+
# These should not report violations as discussed in
34+
# https://github.com/astral-sh/ruff/issues/16373
35+
from importlib.machinery import SourceFileLoader
36+
__doc__ = "..."
37+
__name__ = "a001"
38+
__loader__ = SourceFileLoader(__file__, __name__)
39+
__package__ = None
40+
__spec__ = None

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ impl Violation for BuiltinVariableShadowing {
5959

6060
/// A001
6161
pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: TextRange) {
62+
// These should not report violations as discussed in
63+
// https://github.com/astral-sh/ruff/issues/16373
64+
if matches!(
65+
name,
66+
"__doc__" | "__name__" | "__loader__" | "__package__" | "__spec__"
67+
) {
68+
return;
69+
}
70+
6271
if shadows_builtin(
6372
name,
6473
checker.source_type,

0 commit comments

Comments
 (0)