Skip to content

Commit

Permalink
[pycodestyle] Stabilize: Exempt pytest.importorskip() calls (E402)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jan 8, 2025
1 parent 49c4d12 commit 9cd9f5b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ impl<'a> Checker<'a> {

impl<'a> Visitor<'a> for Checker<'a> {
fn visit_stmt(&mut self, stmt: &'a Stmt) {
let in_preview = self.settings.preview.is_enabled();

// Step 0: Pre-processing
self.semantic.push_node(stmt);

Expand Down Expand Up @@ -514,7 +512,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
|| imports::is_matplotlib_activation(stmt, self.semantic())
|| imports::is_sys_path_modification(stmt, self.semantic())
|| imports::is_os_environ_modification(stmt, self.semantic())
|| (in_preview && imports::is_pytest_importorskip(stmt, self.semantic())))
|| imports::is_pytest_importorskip(stmt, self.semantic()))
{
self.semantic.flags |= SemanticModelFlags::IMPORT_BOUNDARY;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod tests {
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_0.py"))]
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_1.py"))]
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_2.py"))]
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_3.py"))]
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402.ipynb"))]
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
#[test_case(Rule::MultipleStatementsOnOneLineColon, Path::new("E70.py"))]
Expand Down Expand Up @@ -72,7 +73,6 @@ mod tests {
Ok(())
}

#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_3.py"))]
#[test_case(Rule::RedundantBackslash, Path::new("E502.py"))]
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_0.py"))]
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_1.py"))]
Expand Down

0 comments on commit 9cd9f5b

Please sign in to comment.