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.

Assessment

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

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.

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

Dominant language
Python
Stars
279
Forks
72
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from PyCQA/flake8-import-order

All issues in PyCQA/flake8-import-order

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.