Skip to content

Commit

Permalink
Avoid implicit-namespace-package checks for .pyi files (astral-sh#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Jan 31, 2023
1 parent 142b627 commit 84a8b62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Empty file.
21 changes: 11 additions & 10 deletions src/rules/flake8_no_pep420/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ mod tests {
use crate::registry::Rule;
use crate::settings::Settings;

#[test_case(Path::new("test_pass_init"); "INP001_0")]
#[test_case(Path::new("test_fail_empty"); "INP001_1")]
#[test_case(Path::new("test_fail_nonempty"); "INP001_2")]
#[test_case(Path::new("test_fail_shebang"); "INP001_3")]
#[test_case(Path::new("test_ignored"); "INP001_4")]
#[test_case(Path::new("test_pass_namespace_package"); "INP001_5")]
fn test_flake8_no_pep420(path: &Path) -> Result<()> {
#[test_case(Path::new("test_pass_init"), Path::new("example.py"); "INP001_0")]
#[test_case(Path::new("test_fail_empty"), Path::new("example.py"); "INP001_1")]
#[test_case(Path::new("test_fail_nonempty"), Path::new("example.py"); "INP001_2")]
#[test_case(Path::new("test_fail_shebang"), Path::new("example.py"); "INP001_3")]
#[test_case(Path::new("test_ignored"), Path::new("example.py"); "INP001_4")]
#[test_case(Path::new("test_pass_namespace_package"), Path::new("example.py"); "INP001_5")]
#[test_case(Path::new("test_pass_pyi"), Path::new("example.pyi"); "INP001_6")]
fn test_flake8_no_pep420(path: &Path, filename: &Path) -> Result<()> {
let snapshot = format!("{}", path.to_string_lossy());
// Platform-independent paths
let p = PathBuf::from(format!(
"./resources/test/fixtures/flake8_no_pep420/{}/example.py",
path.display()
"./resources/test/fixtures/flake8_no_pep420/{}/{}",
path.display(),
filename.display()
));
let diagnostics = test_path(
p.as_path(),
Expand Down
2 changes: 1 addition & 1 deletion src/rules/flake8_no_pep420/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Violation for ImplicitNamespacePackage {

/// INP001
pub fn implicit_namespace_package(path: &Path, package: Option<&Path>) -> Option<Diagnostic> {
if package.is_none() {
if package.is_none() && path.extension().map_or(true, |ext| ext != "pyi") {
Some(Diagnostic::new(
ImplicitNamespacePackage(fs::relativize_path(path)),
Range::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: src/rules/flake8_no_pep420/mod.rs
expression: diagnostics
---
[]

0 comments on commit 84a8b62

Please sign in to comment.