mirror of https://github.com/astral-sh/ruff
[`pycodestyle`] Stabilize: Exempt `pytest.importorskip` calls (`E402`) (#15338)
This commit is contained in:
parent
8c620b9b4b
commit
9c4d124ba0
|
|
@ -460,8 +460,6 @@ impl<'a> Checker<'a> {
|
||||||
|
|
||||||
impl<'a> Visitor<'a> for Checker<'a> {
|
impl<'a> Visitor<'a> for Checker<'a> {
|
||||||
fn visit_stmt(&mut self, stmt: &'a Stmt) {
|
fn visit_stmt(&mut self, stmt: &'a Stmt) {
|
||||||
let in_preview = self.settings.preview.is_enabled();
|
|
||||||
|
|
||||||
// Step 0: Pre-processing
|
// Step 0: Pre-processing
|
||||||
self.semantic.push_node(stmt);
|
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_matplotlib_activation(stmt, self.semantic())
|
||||||
|| imports::is_sys_path_modification(stmt, self.semantic())
|
|| imports::is_sys_path_modification(stmt, self.semantic())
|
||||||
|| imports::is_os_environ_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;
|
self.semantic.flags |= SemanticModelFlags::IMPORT_BOUNDARY;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ mod tests {
|
||||||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_0.py"))]
|
#[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_1.py"))]
|
||||||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_2.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::ModuleImportNotAtTopOfFile, Path::new("E402.ipynb"))]
|
||||||
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
#[test_case(Rule::MultipleImportsOnOneLine, Path::new("E40.py"))]
|
||||||
#[test_case(Rule::MultipleStatementsOnOneLineColon, Path::new("E70.py"))]
|
#[test_case(Rule::MultipleStatementsOnOneLineColon, Path::new("E70.py"))]
|
||||||
|
|
@ -72,7 +73,6 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case(Rule::ModuleImportNotAtTopOfFile, Path::new("E402_3.py"))]
|
|
||||||
#[test_case(Rule::RedundantBackslash, Path::new("E502.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_0.py"))]
|
||||||
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_1.py"))]
|
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_1.py"))]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue