module-import-not-at-top-of-file
ignore after sys.path.insert
#5557
Labels
module-import-not-at-top-of-file
ignore after sys.path.insert
#5557
Sometimes you need to insert a path to be able to import something that's out of scope from your current file - in which case, the imports must come after the
insert
statement. For example, from Rust's repo:My suggestion is to ignore E402
module-import-not-at-top-of-file
if it comes after asys.path.insert
statement.There are legitimate uses of
sys.path.insert
, but it could be considered a hack or pitfall for new users - so I could understand potentially not wanting this behavior as the default. If this is the case, I would propose one of the following:ignore-after-sys-path-insert
sys.path.insert
usage. The lint could theoretically be kind of smart and suggest possible alternatives for common misuses (adding__init__.py
, importing directly, etc) but that kind of gets into evaluating the contextThe text was updated successfully, but these errors were encountered: