[`pycodestyle`] Stabilize: Exempt `pytest.importorskip` calls (`E402`) (#15338)

This commit is contained in:
Micha Reiser 2025-01-08 09:47:53 +01:00
parent 8c620b9b4b
commit 9c4d124ba0
3 changed files with 2 additions and 4 deletions

View File

@ -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);
@ -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;
}

View File

@ -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"))]
@ -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"))]