Ignore direct root-children in implicit-namespace-package (#2565)

This commit is contained in:
Charlie Marsh 2023-02-04 08:21:24 -05:00 committed by GitHub
parent 7d4f0a8320
commit dd0145624b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -13,7 +13,7 @@ pub fn check_file_path(
// flake8-no-pep420
if settings.rules.enabled(&Rule::ImplicitNamespacePackage) {
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.src) {
if let Some(diagnostic) = implicit_namespace_package(path, package, &settings.project_root, &settings.src) {
diagnostics.push(diagnostic);
}
}

View file

@ -22,11 +22,16 @@ impl Violation for ImplicitNamespacePackage {
pub fn implicit_namespace_package(
path: &Path,
package: Option<&Path>,
project_root: &Path,
src: &[PathBuf],
) -> Option<Diagnostic> {
if package.is_none()
// Ignore `.pyi` files, which don't require an `__init__.py`.
&& path.extension().map_or(true, |ext| ext != "pyi")
// Ignore any files that are direct children of the project root.
&& !path
.parent()
.map_or(false, |parent| parent == project_root)
// Ignore any files that are direct children of a source directory (e.g., `src/manage.py`).
&& !path
.parent()