diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb index 9f9579e77e5dd..2afe9b2da10eb 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb @@ -87,6 +87,37 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a51463ee-091c-44b4-9069-c03bf7e3bf83", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "import pathlib" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ddc937e-6c19-475f-b108-9405aa1af4f1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "285041d2-a76c-4ff3-8ff2-0131bbf66016", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "%%time\n", + "import pathlib" + ] } ], "metadata": { diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 4b6c0e5252395..62de2dfe0d0e4 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -365,6 +365,7 @@ impl<'a> Visitor<'a> for Checker<'a> { self.semantic.flags |= SemanticModelFlags::MODULE_DOCSTRING_BOUNDARY; self.semantic.flags |= SemanticModelFlags::FUTURES_BOUNDARY; if !(self.semantic.seen_import_boundary() + || stmt.is_ipy_escape_command_stmt() || helpers::is_assignment_to_a_dunder(stmt) || helpers::in_nested_block(self.semantic.current_statements()) || imports::is_matplotlib_activation(stmt, self.semantic()) diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402.ipynb.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402.ipynb.snap index 70562983d36e0..7c4447f71c60a 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402.ipynb.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E402_E402.ipynb.snap @@ -24,6 +24,6 @@ E402.ipynb:30:1: E402 Module level import not at top of cell | 30 | import no_ok | ^^^^^^^^^^^^ E402 +31 | +32 | %%time | - -