diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 31069ac6c55fd4..2182e1bcc46a82 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -263,6 +263,34 @@ impl<'a> Checker<'a> { } } +fn is_sys_path_modification(stmt: &Stmt, semantic: &SemanticModel) -> bool { + let Stmt::Expr(ast::StmtExpr { value, range: _ }) = stmt else { + return false; + }; + let Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() else { + return false; + }; + semantic + .resolve_call_path(func.as_ref()) + .is_some_and(|call_path| { + matches!( + call_path.as_slice(), + [ + "sys", + "path", + "append" + | "insert" + | "extend" + | "remove" + | "pop" + | "clear" + | "reverse" + | "sort" + ] + ) + }) +} + impl<'a, 'b> Visitor<'b> for Checker<'a> where 'b: 'a, @@ -306,6 +334,7 @@ where if !self.semantic.seen_import_boundary() && !helpers::is_assignment_to_a_dunder(stmt) && !helpers::in_nested_block(self.semantic.current_statements()) + && !is_sys_path_modification(stmt, self.semantic()) { self.semantic.flags |= SemanticModelFlags::IMPORT_BOUNDARY; }