Skip to content

support alternate lines for noqa declaration of import order violations #226

@jvanasco

Description

@jvanasco

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: PyCQA/flake8#1993

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions