Skip to content

E402 false positive with cell magics in Jupyter notebooks #10357

@jamesmyatt

Description

@jamesmyatt

The E402 rule should permit cell magics as well as comments before the import statements. The cell magics must come first.

e.g.

%%time
import expensive_module

I suspect that line magics should also be permitted before import statements, like:

%time import expensive_module
import cheap_module

Error message is:

E402 Module level import not at top of cell

Metadata

Metadata

Assignees

Labels

notebookRelated to (Jupyter) notebooksruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions