Skip to content

Commit 2d3dc7c

Browse files
committed
[flake8-builtins] Default to non-strict checking (A005)
1 parent f8093b6 commit 2d3dc7c

File tree

7 files changed

+19
-46
lines changed

7 files changed

+19
-46
lines changed

crates/ruff/tests/lint.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,11 +2404,7 @@ fn a005_module_shadowing_strict_default() -> Result<()> {
24042404
----- stdout -----
24052405
abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
24062406
collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module
2407-
collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
2408-
foobar/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
2409-
foobar/collections/__init__.py:1:1: A005 Module `collections` shadows a Python standard-library module
2410-
foobar/collections/abc/__init__.py:1:1: A005 Module `abc` shadows a Python standard-library module
2411-
Found 6 errors.
2407+
Found 2 errors.
24122408
24132409
----- stderr -----
24142410
");

crates/ruff/tests/snapshots/show_settings__display_default_settings.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ linter.flake8_bandit.check_typed_exception = false
228228
linter.flake8_bugbear.extend_immutable_calls = []
229229
linter.flake8_builtins.builtins_allowed_modules = []
230230
linter.flake8_builtins.builtins_ignorelist = []
231-
linter.flake8_builtins.builtins_strict_checking = true
231+
linter.flake8_builtins.builtins_strict_checking = false
232232
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false
233233
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
234234
linter.flake8_copyright.author = none

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ use crate::settings::LinterSettings;
2323
/// Standard-library modules can be marked as exceptions to this rule via the
2424
/// [`lint.flake8-builtins.builtins-allowed-modules`] configuration option.
2525
///
26-
/// By default, only the last component of the module name is considered, so `logging.py`,
27-
/// `utils/logging.py`, and `utils/logging/__init__.py` would all clash with the builtin `logging`
28-
/// module. With the [`lint.flake8-builtins.builtins-strict-checking`] option set to `false`, the
29-
/// module path is considered, so only a top-level `logging.py` or `logging/__init__.py` will
30-
/// trigger the rule and `utils/logging.py`, for example, would not. In preview mode, the default
31-
/// value of [`lint.flake8-builtins.builtins-strict-checking`] is `false` rather than `true` in
32-
/// stable mode.
26+
/// By default, the module path relative to the project root or [`src`] directories is considered,
27+
/// so a top-level `logging.py` or `logging/__init__.py` will clash with the builtin `logging`
28+
/// module, but `utils/logging.py`, for example, will not. With the
29+
/// [`lint.flake8-builtins.builtins-strict-checking`] option set to `true`, only the last component
30+
/// of the module name is considered, so `logging.py`, `utils/logging.py`, and
31+
/// `utils/logging/__init__.py` will all trigger the rule.
3332
///
3433
/// This rule is not applied to stub files, as the name of a stub module is out
3534
/// of the control of the author of the stub file. Instead, a stub should aim to

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Settings for the `flake8-builtins` plugin.
22
3-
use crate::{display_settings, settings::types::PreviewMode};
3+
use crate::display_settings;
44
use ruff_macros::CacheKey;
55
use std::fmt::{Display, Formatter};
66

@@ -11,16 +11,6 @@ pub struct Settings {
1111
pub builtins_strict_checking: bool,
1212
}
1313

14-
impl Settings {
15-
pub fn new(preview: PreviewMode) -> Self {
16-
Self {
17-
builtins_ignorelist: Vec::new(),
18-
builtins_allowed_modules: Vec::new(),
19-
builtins_strict_checking: preview.is_disabled(),
20-
}
21-
}
22-
}
23-
2414
impl Display for Settings {
2515
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2616
display_settings! {

crates/ruff_workspace/src/configuration.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ impl Configuration {
234234

235235
let rules = lint.as_rule_table(lint_preview)?;
236236

237-
let flake8_builtins = lint
238-
.flake8_builtins
239-
.map(|builtins| builtins.into_settings(lint_preview))
240-
.unwrap_or_else(|| {
241-
ruff_linter::rules::flake8_builtins::settings::Settings::new(lint_preview)
242-
});
243-
244237
// LinterSettings validation
245238
let isort = lint
246239
.isort
@@ -342,7 +335,10 @@ impl Configuration {
342335
.flake8_bugbear
343336
.map(Flake8BugbearOptions::into_settings)
344337
.unwrap_or_default(),
345-
flake8_builtins,
338+
flake8_builtins: lint
339+
.flake8_builtins
340+
.map(Flake8BuiltinsOptions::into_settings)
341+
.unwrap_or_default(),
346342
flake8_comprehensions: lint
347343
.flake8_comprehensions
348344
.map(Flake8ComprehensionsOptions::into_settings)

crates/ruff_workspace/src/options.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ruff_linter::rules::{
2828
pycodestyle, pydoclint, pydocstyle, pyflakes, pylint, pyupgrade, ruff,
2929
};
3030
use ruff_linter::settings::types::{
31-
IdentifierPattern, OutputFormat, PreviewMode, PythonVersion, RequiredVersion,
31+
IdentifierPattern, OutputFormat, PythonVersion, RequiredVersion,
3232
};
3333
use ruff_linter::{warn_user_once, RuleSelector};
3434
use ruff_macros::{CombineOptions, OptionsMetadata};
@@ -1144,30 +1144,22 @@ pub struct Flake8BuiltinsOptions {
11441144
/// List of builtin module names to allow.
11451145
pub builtins_allowed_modules: Option<Vec<String>>,
11461146
#[option(
1147-
default = r#"true"#,
1147+
default = r#"false"#,
11481148
value_type = "bool",
1149-
example = "builtins-strict-checking = false"
1149+
example = "builtins-strict-checking = true"
11501150
)]
11511151
/// Compare module names instead of full module paths.
11521152
///
11531153
/// Used by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).
1154-
///
1155-
/// In preview mode the default value is `false` rather than `true`.
11561154
pub builtins_strict_checking: Option<bool>,
11571155
}
11581156

11591157
impl Flake8BuiltinsOptions {
1160-
pub fn into_settings(
1161-
self,
1162-
preview: PreviewMode,
1163-
) -> ruff_linter::rules::flake8_builtins::settings::Settings {
1158+
pub fn into_settings(self) -> ruff_linter::rules::flake8_builtins::settings::Settings {
11641159
ruff_linter::rules::flake8_builtins::settings::Settings {
11651160
builtins_ignorelist: self.builtins_ignorelist.unwrap_or_default(),
11661161
builtins_allowed_modules: self.builtins_allowed_modules.unwrap_or_default(),
1167-
builtins_strict_checking: self
1168-
.builtins_strict_checking
1169-
// use the old default of true on non-preview
1170-
.unwrap_or(preview.is_disabled()),
1162+
builtins_strict_checking: self.builtins_strict_checking.unwrap_or_default(),
11711163
}
11721164
}
11731165
}

ruff.schema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)