Skip to content

Conversation

@dhruvmanila
Copy link
Member

Summary

This PR fixes the bug to allow Ipython escape commands to be present before an import statement and avoid raising E402.

fixes: #10357

Test Plan

Add test case and make sure they don't raise the E402 violation.

On main, we get the following:

crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb:cell 8:2:1: E402 Module level import not at top of cell
  |
1 | %%time
2 | import pathlib
  | ^^^^^^^^^^^^^^ E402
  |

crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.ipynb:cell 10:3:1: E402 Module level import not at top of cell
  |
1 | %%time
2 | %%time
3 | import pathlib
  | ^^^^^^^^^^^^^^ E402

@dhruvmanila dhruvmanila added bug Something isn't working rule Implementing or modifying a lint rule and removed bug Something isn't working labels Mar 24, 2024
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila dhruvmanila merged commit c447454 into main Mar 24, 2024
@dhruvmanila dhruvmanila deleted the dhruv/e402-ipy-stmt-fix branch March 24, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E402 false positive with cell magics in Jupyter notebooks

2 participants