PyCQA / PyCQA/flake8-import-order

support alternate lines for noqa declaration of import order violations

Open
#226 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
280
Forks
72
Avg merge
12h 24m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the plugin's handling of I100 and E402 noqa declarations, using the current and requested examples in this issue as behavioral references. The work is done when noqa directives on the warning-configuration imports can suppress violations on later imports, while existing inline suppressions continue to work and obsolete ignores can be removed safely.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.