Skip to content

Commit

Permalink
[E402] Allow cell magics before an import (#10545)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila authored Mar 24, 2024
1 parent 895d9df commit c447454
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|


0 comments on commit c447454

Please sign in to comment.