Is there option to not fully ignore E402, but partially ignore it the file use notebook style block of code (supported to run as block on VSCode). One of the most common style is # %%.
Some user might want that autopep did not fix E402 outside block comment if the parameter used, but fix it as long as inside one block.
Python Code
# %%
import numpy as np # should not be fixed because import already on top of the block and file
...
# %%
...
# %%
import os # should not be fixed because import already on top of the block
import sys
# %%
... # should be fixed, because import not on top
import os
import sys
Is there option to not fully ignore E402, but partially ignore it the file use notebook style block of code (supported to run as block on VSCode). One of the most common style is
# %%
.isort solve it using
treat_comments_as_code = ["# %%"]
as explained in https://github.com/PyCQA/isort/issues/1338 and here.Some user might want that autopep did not fix E402 outside block comment if the parameter used, but fix it as long as inside one block.
Python Code
Command Line and Configuration
pyproject.toml
Command Line
Your Environment