support alternate lines for noqa declaration of import order violations
I have a few programs that utilize upstream packages that emit warnings on initial import (mostly pkg_resources deprecations right now). This causes issues with commandline scripts, because the warnings are sent to STDERR, suggesting a failure.
The only way to suppress these warnings entirely within Python code, is to immediately import warnings and configure warnings.ignore.
There are 2 common ways to do this:
1- the initial lines import a _warnings_disable.py file that imports and configure ignores/logging. 2- the initial lines import warnings and configure ignores/logging before importing the offending packages.
In the first example, I100 must be placed on the first import AFTER importing the out-of-place lines.
In the second example, E402 must be placed on each import after the out-of-place lines.
It would be beneficial if the ignore statements could instead be placed on the out-of-place lines, so they are inherently removed when the code is updated. Under the current implementation, stray ignores are likely to remain when the code is maintained and the warnings configuration is removed.
Current behavior:
from . import _configure_warnings # noqa: F401
import datetime # noqa: I100
Requested behavior:
from . import _configure_warnings # noqa: F401, I10X
import datetime
I noted I10X because a feature like this might be better implemented with a new code.
In both situations, the offending anti-pattern is properly documented. The new functionality simply allows the noqa to be declared on alternate line(s).
Thank you for your consideration.
was: https://github.com/PyCQA/flake8/issues/1993
This is tricky. flake8 itself has a layer which checks noqa and decides whether or not to report something. That said, this plugin also checks whether an error is ignored itself using a (likely) faulty regular expression.
That said, right now any of these violations are reported on the line of the offending import(s).
Bundling this into noqa is likely to cause a lot of issues because sadly a lot of other tools have decided to adopt noqa as well when it wasn't intended to be a generic disabling comment.
A better idea would be to likely have something like Black's # fmt: off/# fmt: on to mark areas as "ignored". That said, I don't have the time at the moment to implement this. I'm happy to review a PR that implements this though
Thanks for the quick reply. I don't have time to implement this right now myself, but I'll toss it on my todo list and will hopefully get to it soon (unless someone else gets to it first - we can hope!).
Since I have your attention now, does this look like a good syntax ?
# flake8-import-order: off
# flake8-import-order: on
Yeah that seems fine. It's explicit and obvious I'd hope so hopeful simple enough