Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E402] Allow cell magics before an import #10545

Merged
merged 1 commit into from
Mar 24, 2024
Merged

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
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
17 checks passed
@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
1 participant