[flake8-builtins] Disapply A005 to stub files (#15350)

This commit is contained in:
Alex Waygood 2025-01-08 12:59:27 +00:00 committed by GitHub
parent 1447553bc2
commit ee9a912f47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1 @@
# A005 does not apply to stub files!

View file

@ -36,6 +36,10 @@ mod tests {
Rule::StdlibModuleShadowing,
Path::new("A005/modules/package/bisect.py")
)]
#[test_case(
Rule::StdlibModuleShadowing,
Path::new("A005/modules/package/collections.pyi")
)]
#[test_case(
Rule::StdlibModuleShadowing,
Path::new("A005/modules/_abc/__init__.py")

View file

@ -23,6 +23,10 @@ use crate::settings::types::PythonVersion;
/// Standard-library modules can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-allowed-modules`] configuration option.
///
/// This rule is not applied to stub files, as the name of a stub module is out
/// of the control of the author of the stub file. Instead, a stub should aim to
/// faithfully emulate the runtime module it is stubbing.
///
/// ## Options
/// - `lint.flake8-builtins.builtins-allowed-modules`
#[derive(ViolationMetadata)]
@ -45,7 +49,7 @@ pub(crate) fn stdlib_module_shadowing(
allowed_modules: &[String],
target_version: PythonVersion,
) -> Option<Diagnostic> {
if !PySourceType::try_from_path(path).is_some_and(PySourceType::is_py_file_or_stub) {
if !PySourceType::try_from_path(path).is_some_and(PySourceType::is_py_file) {
return None;
}

View file

@ -0,0 +1,4 @@
---
source: crates/ruff_linter/src/rules/flake8_builtins/mod.rs
---