E402: Imports after adding to `sys.path`
marsfan opened this issue · comments
As an example, consider the following snippet from a Sphinx conf.py file where module
is located one folder up from conf.py:
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
import module.submodule
pycodestyle
complains that the module level imports are not at the top of the file.
This is especially significant as some formatters (specifically autopep8) use pycodestyle as their backend, and "fixing" the formatting will result in the code no longer functioning.
This is similar to the dunder issue that was fixed in #613, except it deals with adding to the path instead of including dunder variables, thus the fix will likely be similar .
this is intentional -- sys.path.insert
is a hack