Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

@emmanuel-ferdman emmanuel-ferdman commented Sep 24, 2025

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Previously, a # pylint: disable=wrong-import-position pragma on a non-import statement would incorrectly suppress wrong-import-position messages for all subsequent import statements in the module. This violated the expected behavior where single-line pragmas should only affect their own line. The fix changes the message enablement check from using the first non-import node's line number to using the current import node's line number, ensuring proper pragma isolation.

Example:

import logging

logger = logging.getLogger()  # pylint: disable=wrong-import-position
import os  # This should trigger wrong-import-position
import sys  # This should trigger wrong-import-position

Expected Output:

  • Before: No wrong-import-position messages (incorrect behavior)
  • After: wrong-import-position messages for both import os and import sys (correct behavior)

Closes #10589

@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 95.98%. Comparing base (68ab16f) to head (771ac7c).
⚠️ Report is 136 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10590      +/-   ##
==========================================
+ Coverage   95.95%   95.98%   +0.03%     
==========================================
  Files         176      176              
  Lines       19455    19561     +106     
==========================================
+ Hits        18668    18776     +108     
+ Misses        787      785       -2     
Files with missing lines Coverage Ξ”
pylint/checkers/imports.py 94.88% <100.00%> (+0.01%) ⬆️

... and 33 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if the 'right way to fix this' isn't to return uninferable in astroid instead. Because it's possible that a function validly return an empty list.

@emmanuel-ferdman
Copy link
Contributor Author

@Pierre-Sassoulas Should it be fixed in the astroid library itself or using an astroid hook in pylint library?

@Pierre-Sassoulas
Copy link
Member

Astroid itself, we're the same maintainers and 99% of astroid user are also pylint users :)

@emmanuel-ferdman emmanuel-ferdman changed the title fix: avoid false positive unbalanced-tuple-unpacking for cross-module function calls fix: scope wrong-import-position pragma to specific line only Sep 25, 2025
@emmanuel-ferdman
Copy link
Contributor Author

@Pierre-Sassoulas thanks for the guidance! I opened a PR in the astroid repo for this issue. Since this PR is already open, I also included a fix for another pylint issue. Apologies for the force push πŸ™Œ

@github-actions

This comment has been minimized.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

In the future it would be better to open a new one as that makes communication scoped a bit better. We can still continue with this one though :)

Comment on lines 19 to 23
import json # pylint: disable=wrong-import-position

# Test that subsequent imports are not affected by the pragma above
import csv # [wrong-import-position]
import re # [wrong-import-position]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the correct behaviour, or at least should be considered a breaking change?

The test you're changing above seems to explicitly test for this case:
A previous disable should also count for subsequent imports.

@Pierre-Sassoulas What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, yes, we reviewed independently but I think we said the same thing..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pierre-Sassoulas You approved, but this question still stands I guess? We're now actively removing support for behaviour for which we had a test. I'm not sure why we added this behaviour in the first place, but considering we are changing behaviour isn't this a breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we didn't say the same thing after all. It seems we can't have an easy implementation of both "disable on a statement" and "any disable prevent all further wrong-import-position" so there's a decision to take here. And we might have to do the hard implementation, especially since I don't think isort or ruff deal with intertwined statements in imports (?).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current PR does:

The fix changes the message enablement check from using the first non-import node's line number to using the current import node's line number, ensuring proper pragma isolation.

Perhaps we can it to:

The fix changes the message enablement check from no longer working on non-import statements for this message. A pragma will disable from the current import statement until further statements, ensuring proper pragma isolation.

if self.linter.is_message_enabled(
"wrong-import-position", self._first_non_import_node.fromlineno
):
if self.linter.is_message_enabled("wrong-import-position", node.fromlineno):
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instinctively I would say the fix need to be a lot more complex than that. If one line is disabled it means not only that the message shouldn't be raised for it but also that other line should not raise if the only issue for them it the disabled line.

i.e. the expected is

import a
import b
import c
import b  # [wrong-import-position]
import a  # [wrong-import-position]
import c 
import b  # pylint: disable=wrong-import-position
import a  
import c  
import b  # pylint: disable=wrong-import-position
import c   # [wrong-import-position]
import a   # [wrong-import-position]

Tbf, I don't think we should sweat other this, maybe we need to abandon the pylint disable system for this specific error message, and take the isort/ruff "I" disable into account, or drop the message entirely, or integrate ruff plus autofix and drop isort, or integrate both ruff and isort... I don't see a fix for this being super impactful in the mid term.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand your comment, and I think taking into accounts other tools setting is bit too much work for @emmanuel-ferdman πŸ˜…

@emmanuel-ferdman Do you think we can fix your issue while still keeping the behaviour as being tested in the test? I agree that a disable on a non-import makes no sense, but perhaps we can fix it with a smaller scope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that the effort to fix this at all is not worth it as we have ruff and isort for reordering import, having working disable in pylint or coordinating multiple tools that check this message does not bring a lot of value imo. (Maybe we can even remove the check entirely for 4.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielNoord @Pierre-Sassoulas Thanks for the feedback πŸ™Œ
From issue #10589 and seeing that other pylint rules are line-based, I assumed this was a bug. But I understand that wrong-import-position might be different since it's about import ordering patterns. What should we do here? I'm happy to try and implement whatever you think is best.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for marking an issue as ready for PR when clearly it wasn't well specified @emmanuel-ferdman. Or thank you for making the fix and making us realize what actually fixing this bug imply. I think we should close because there's probably better use for your time. Right now I'm more and more convinced that we should either drop isort and wrong-import-position (import time at startup could make this a big change for users) or add ruff (using ruff and isort as optional dependencies instead of isort as mandatory dependency would open a world of possibilities once the wrong-import-position proof of concept is validated). In all case this mean this fix is not going to be used much. Need some other maintainers opinion about it and it's probably an idea for pylint 5.0 anyway (that I should open an issue for if Daniel don't think it's trash).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with removing the dependency on isort.

It fails logical to let those concerns be dealt with by a separate tool with its own configuration and/or ignores. Wondering what other maintainers think.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs decision πŸ”’ Needs a decision before implemention or rejection label Sep 26, 2025
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.0 milestone Sep 26, 2025
@ruck94301
Copy link

ruck94301 commented Sep 26, 2025

@Pierre-Sassoulas, you gave 4 examples above (importing a, b, & c).
Those seem like wrong-import-order C0411, not wrong-import-position C0413.
I mean, I think they are actually not the expected. But if you change to the pragma and expected messages to wrong-import-order, yes that's the expected.

The original bug report is about wrong-import-position, which maybe doesn't require sorting & other complexities?

At any rate, thanks for taking my report seriously, I appreciate that! :)

@Pierre-Sassoulas
Copy link
Member

Ha, indeed you're right, my bad. Well the fix LGTM as is after a second take. I'm going to create an issue for the unrelated discussion.

@Pierre-Sassoulas Pierre-Sassoulas added Bug πŸͺ² backport maintenance/4.0.x and removed Needs decision πŸ”’ Needs a decision before implemention or rejection labels Sep 27, 2025
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 4.0.0, 3.3.9 Sep 27, 2025
@ruck94301
Copy link

ruck94301 commented Sep 29, 2025

Sorry to risk additional confusion. I will try hard to be clear.
The issue in this bug is regarding C0413 wrong-import-position, not C0411 wrong-import-order. That has already been clarified.

However, during the above conversation, I agreed with the expectations of a different condition, C0411 wrong-import-order, as shown with importing a, b, & c in different orders.

import os  # [wrong-import-order]
import logging  # [wrong-import-order]
import sys  

which seemed reasonable. But OTOH, this also seems reasonable to the user:

import os
import logging  # [wrong-import-order]
import sys  

So, which is actually implemented? Easy to check...
Neither. C0411 (in pylint 3.3.7) doesn't seem to verify the sort order of the libraries within the three "families"-- at least the standard libraries family. Because I'm seeing no C0411 on the following.

import os
import logging
import sys  

I DO get C0411 when I, for example, import a third-party lib in the wrong place.

import os
import requests
import logging  # [wrong-import-order]
import sys  # [wrong-import-order]

Maybe C0411 doesn't attempt to validate the "alphabetical" sort order recommendation of PEP 8, and concerns itself only with whether the three sets of imports are correctly organized per PEP 8 like (1) standard lib imports, (2) related 3rd party lib imports (3) Local application/library specific imports.
So even though I cannot see how this is relevant to C0413, I wanted to clarify C0411 existing behavior in 3.3.7. Hope this helps. LMK if you think I'm misunderstanding something.
Best Regards,
John

@jacobtylerwalls
Copy link
Member

This still seems like a breaking change?

We're removing a dubious feature. Maybe we can avoid backporting in that case. It was added in #1337 without much discussion.

@emmanuel-ferdman emmanuel-ferdman changed the title fix: scope wrong-import-position pragma to specific line only fix: support block-level wrong-import-position pragma suppression Oct 19, 2025
@emmanuel-ferdman
Copy link
Contributor Author

For now, I followed @Pierre-Sassoulas’s suggestion: a pragma on the non-import line that breaks the import block suppresses the following imports until the next non-import. Inline disables on the import line still work as before. Please let me know what you think.

Example:

import os
import sys

# First non-import with pragma - suppresses following imports
CONSTANT1 = "value1"  # pylint: disable=wrong-import-position
import json
import csv

# Second non-import without pragma - imports after this should be flagged
CONSTANT2 = "value2"
import logging

# Third non-import with pragma - suppresses following imports again
CONSTANT3 = "value3"  # pylint: disable=wrong-import-position
import pathlib
import random

# Fourth non-import without pragma - import after this should be flagged
CONSTANT4 = "value4"
import re

Output:

input.py:14:0: C0413: Import "import logging" should be placed at the top of the module (wrong-import-position)
input.py:23:0: C0413: Import "import re" should be placed at the top of the module (wrong-import-position)

@github-actions

This comment has been minimized.

@jacobtylerwalls jacobtylerwalls modified the milestones: 4.0.2, 4.0.3 Oct 20, 2025
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 4.0.3, 4.0.4 Nov 9, 2025
@emmanuel-ferdman
Copy link
Contributor Author

@Pierre-Sassoulas @jacobtylerwalls Sorry to follow up again, but I'm looking for feedback on new approch and guidance on the next step when you get a chance to look into this πŸ˜„

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current approach but I'm not sure we had an agreement about what to do as Jacob/Daniel liked/approved the previous one. It's a check I very rarely disable personally so I'm not going to die on any hill.

DanielNoord
DanielNoord previously approved these changes Nov 19, 2025
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!


# Pragma on non-import suppresses following imports until next non-import
CONSTANT_A = False # pylint: disable=wrong-import-position
import time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case where this import is indented under a try or an if? I'm showing that this is not currently handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobtylerwalls You are correct - there is inconsistent behavior and the question is what is the expected behaviour?

For the following example:

import os
import sys

CONSTANT = True  # pylint: disable=wrong-import-position

try:  # or if/for/while/with/def/class
    import json
...

import time  # <-- Is this flagged?

The currently PR code produce the following behaviour:

Structure import time flagged?
try NO
if YES
for YES
while YES
with NO
def YES
class YES

Could you please help here define the expected behavior here?

Copy link
Member

@jacobtylerwalls jacobtylerwalls Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to just define what a consecutive import is and then stick to the letter of the rule. (We disable until the consecutive imports stop.)

For me, these two are consecutive imports:

try:
    import black
except ImportError:
    import ruff

import time

These two are not:

try:
    import black
except ImportError:
    HAS_BLACK = False
else:
    HAS_BLACK = True

import time

Same with if/with/for/while:

if PY314:
    import annotationlib

import time  # consecutive

def and class can't be empty, they must at least have a .../pass

if PY314:
    import annotationlib

    def get_annotations():
        pass  # a non-import statement

import time  # no longer consecutive

Does that seem sane?

Copy link

@ruck94301 ruck94301 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobtylerwalls provides 4 examples of what he expects from the wrong-import-position rule itself.
I think you guys are discussing CHANGING the behavior, so these examples are not expected to match pylint 4.0.3. Nevertheless, it seems useful to state what existing 4.0.3 behavior is.

Your Expected 1 agrees with pylint 4.0.3.

Your Expected 2 disagrees. It seems like 4.0.3 treats the whole try-block as an import (a β€œwrong-import-position import”?, a WIPI?), because the try-clause smells like an import. The contents of the except-clause and else-clause are ignored. See tests/functional/w/wrong_import_position2.py

"""Checks import order rule with nested non_import sentence"""
# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level
try:
    from sys import argv
except ImportError:
    pass
else:
    pass

import os

Also note that the try clause could contain non-imports before and after the β€œimport black”, but those would not matter to the wrong-import-position algorithm. The try-block would STILL be assessed as an import for the purpose of this rule.
However if the try-clause DIDN'T contain an import, then yeah, the try block WOULDN'T smell like a WIPI.

Your Expected 3 -- disagrees with 4.0.3. ANY if-block is a non-import (non-WIPI) see tests/functional/w/wrong_import_position14.py

"""Checks import position rule"""
# pylint: disable=unused-import,undefined-variable,import-error
if x:
    import os
import y  # [wrong-import-position]

Your Expected 4 -- agrees, but still, function def in the content of the if-block doesn't matter.

If I was king, I think I wouldn't even try to parse the contents of try/if/while/for/with. I'd treat them (their block, that is) as non-import regardless of content -- that is, just like the if-statement seems to be treated now.
And report any following module-level imports as wrong-import-position.
And a disable-pragma on the try/if/while/for/with statement, or a disable-next before, should cause the whole block to be treated as if it was an import.
So, I'm not challenging the sanity of your expectations, but I'm offering a different (sane?) POV.
This too would be behavior changing because existing wrong_import_position2.py would be broken :-/

Copy link

@ruck94301 ruck94301 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, another POV -- I could see an argument for flattening try-blocks and ignoring its exception paths.
Replace

try:
    statement 1
except:
    statement 2
else:
    statement 3
finally:
    statement 4

with

statement 1
statement 3
statement 4

because you're representing the success path. And you'd want to recurse to handle the try inside try.
Meh, seems too clever by half. If I had a vote, I'd oppose descending below the first level of the ast nodes. Treat a 'try' node as a non-import.

And I'm still not seeing a good rationale for flattening with statements to be anything other than a non-import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobtylerwalls Thanks for the detailed explanation! Before I implement, I want to confirm: @ruck94301 suggested a simpler approach - treat all control-flow blocks as non-imports regardless of content. Would you prefer that simpler approach, or should I implement your 'consecutive imports' logic that inspects block contents?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found @ruck94301's reminder to keep it not clever compelling.

Let's do this:

I think I wouldn't even try to parse the contents of try/if/while/for/with. I'd treat them (their block, that is) as non-import regardless of content -- that is, just like the if-statement seems to be treated now.

Most important for me is just treating try and if similarly.

@jacobtylerwalls jacobtylerwalls removed the Needs decision πŸ”’ Needs a decision before implemention or rejection label Nov 30, 2025
@jacobtylerwalls jacobtylerwalls modified the milestones: 4.0.4, 4.1.0 Nov 30, 2025
@github-actions

This comment has been minimized.

@emmanuel-ferdman
Copy link
Contributor Author

@jacobtylerwalls Done. All control-flow blocks (try/if/for/while/with/match) are now treated as non-imports regardless of content. Updated tests cover all block types.

@jacobtylerwalls
Copy link
Member

Thanks. Now, with the benefit of the primer result, I'm realizing that my advice about handling try & if identically was motivated by making the pragma behave predictably, not causing a behavior change for the message itself without a pragma. That primer result looks like a pretty big breaking change.

What do you recommend?

@emmanuel-ferdman
Copy link
Contributor Author

@jacobtylerwalls Yeah, I see what you mean. In Django, I see plenty of cases where we can't fix the code by moving the import, only with disable rule, for example:

try:
    import MySQLdb
except ImportError:
    raise Error("Install mysql")

from MySQLdb.constants import x  # Should this be flagged?

I did some research on how other linters/formatters handle this. I tried to compare them against the different versions of this PR:

  • flake8/pycodestyle: Uses a line-based approach. Lines starting with allowed keywords (try, except, else, finally, with, if, elif) don't trigger the import boundary. Indented code is ignored entirely. Note that match is not in the allowed keywords list.
  • astral-sh/ruff: Allows imports after try, if, with, match blocks; flags for, while, assignments, function calls. If a statement is inside a try, if, with, or match block, don't set the import boundary. Also has special exceptions for sys.path, os.environ, dunder assignments, etc.
  • Pylint (original): Exempts try blocks containing imports, with, and match; pragma on first non-import line suppresses all subsequent imports.
  • Pylint (PR v1 - line-pragma): Same detection as original, but pragma only suppresses the exact line it's on.
  • Pylint (PR v2 - block-pragma): Same detection as original, but pragma suppresses imports until the next non-import line.
  • Pylint (PR v3 - current): Removes all exemptions, flags everything including try/with/match; keeps block-pragma from v2.
  • Pylint (PR v4 - new): Exempts try, if, with, match blocks from marking the import boundary. Flags for, while, class, def, async def, assignments, and function calls. Also fixes bug where async def was not detected as marking the boundary. Keeps block-pragma from v2.

The table I got:

Test Ruff flake8 pycodestyle Pylint Orig PR v1 PR v2 PR v3 PR v4 (new)
try_with_import βœ… βœ… βœ… βœ… βœ… βœ… ❌ βœ…
try_without_import βœ… βœ… βœ… ❌ ❌ ❌ ❌ βœ…
try_finally βœ… βœ… βœ… βœ… βœ… βœ… ❌ βœ…
try_else βœ… βœ… βœ… βœ… βœ… βœ… ❌ βœ…
if_with_import βœ… βœ… βœ… ❌ ❌ ❌ ❌ βœ…
if_without_import βœ… βœ… βœ… ❌ ❌ ❌ ❌ βœ…
if TYPE_CHECKING βœ… βœ… βœ… ❌ ❌ ❌ ❌ βœ…
else βœ… βœ… βœ… ❌ ❌ ❌ ❌ βœ…
for ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
while ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
with βœ… βœ… βœ… βœ… βœ… βœ… ❌ βœ…
match βœ… ❌ ❌ βœ… βœ… βœ… ❌ βœ…
class ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
def ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
async def ❌ ❌ ❌ βœ… βœ… βœ… βœ… ❌
decorated func ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
assignment ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
funcall ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌

Legend - βœ… = allowed, ❌ = flagged, see test examples below.

Import sorters:

  • reorder-python-imports: Imports after non-whitespace lines will be ignored. Imports inside try/except will not be changed.
  • facebook/usort: Treats code as "block boundaries" - imports after try/except are separate blocks.
  • flake8-import-order: "Conditional imports in module scope will be ignored.
  • isort: Doesn't handle try/except blocks well, recommends # isort:skip_file.
  • PEP 8 itself: Shows try: import x except ImportError as acceptable pattern.

Looks like every tool either allows imports after try/except, ignores them, or treats them as separate blocks. None flag them as errors. So I think we should exempt try, if, with, match blocks and flag everything else. I already implemented the changed (v4) - What do you think?

Test examples:

try_with_import
import os

try:
    import json
except ImportError:
    pass

import sys  # <- flagged?
try_without_import
import os

try:
    x = 1
except Exception:
    pass

import sys  # <- flagged?
try_finally
import os

try:
    import json
finally:
    pass

import sys  # <- flagged?
try_else
import os

try:
    import json
except ImportError:
    pass
else:
    x = 1

import sys  # <- flagged?
if_with_import
import os

if True:
    import json

import sys  # <- flagged?
if_without_import
import os

if True:
    x = 1

import sys  # <- flagged?
if TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from collections import OrderedDict

import sys  # <- flagged?
else
import os

if False:
    pass
else:
    x = 1

import sys  # <- flagged?
for
import os

for i in []:
    pass

import sys  # <- flagged?
while
import os

while False:
    pass

import sys  # <- flagged?
with
import os

with open("/dev/null"):
    pass

import sys  # <- flagged?
match
import os

match 1:
    case 1:
        pass

import sys  # <- flagged?
class
import os

class Foo:
    pass

import sys  # <- flagged?
def
import os

def foo():
    pass

import sys  # <- flagged?
async def
import os

async def foo():
    pass

import sys  # <- flagged?
decorated func
import os

def decorator(f):
    return f

@decorator
def foo():
    pass

import sys  # <- flagged?
assignment
import os

x = 1

import sys  # <- flagged?
funcall
import os

print("hello")

import sys  # <- flagged?

@github-actions
Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on ansible:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "from ansible.utils.display import Display" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/executor/module_common.py#L67
  2. wrong-import-position:
    Import "import importlib.util" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/executor/module_common.py#L69
  3. wrong-import-position:
    Import "import importlib.machinery" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/executor/module_common.py#L70
  4. wrong-import-position:
    Import "from ansible.galaxy.collection.gpg import get_signature_from_source" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/providers.py#L21
  5. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.dataclasses import Candidate, Requirement" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/providers.py#L22
  6. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.versioning import is_pre_release, meets_requirements" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/providers.py#L26
  7. wrong-import-position:
    Import "from ansible.utils.version import SemanticVersion, LooseVersion" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/providers.py#L30
  8. wrong-import-position:
    Import "from ansible.errors import AnsibleError, AnsibleAssertionError" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L29
  9. wrong-import-position:
    Import "from ansible.galaxy.api import GalaxyAPI" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L30
  10. wrong-import-position:
    Import "from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L31
  11. wrong-import-position:
    Import "from ansible.module_utils.common.arg_spec import ArgumentSpecValidator" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L32
  12. wrong-import-position:
    Import "from ansible.utils.collection_loader import AnsibleCollectionRef" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L33
  13. wrong-import-position:
    Import "from ansible.utils.display import Display" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L34
  14. wrong-import-position:
    Import "from .. import collection as _glx_coll_mod" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/dataclasses.py#L36
  15. wrong-import-position:
    Import "from ansible.galaxy.collection.galaxy_api_proxy import MultiGalaxyAPIProxy" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/__init__.py#L18
  16. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.providers import CollectionDependencyProvider" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/__init__.py#L19
  17. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.reporters import CollectionDependencyReporter" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/__init__.py#L20
  18. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.resolvers import CollectionDependencyResolver" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/dependency_resolution/__init__.py#L21
  19. wrong-import-position:
    Import "from ansible import context" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L28
  20. wrong-import-position:
    Import "from ansible.errors import AnsibleError" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L29
  21. wrong-import-position:
    Import "from ansible.galaxy import get_collections_galaxy_meta_info" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L30
  22. wrong-import-position:
    Import "from ansible.galaxy.api import should_retry_error" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L31
  23. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.dataclasses import _GALAXY_YAML" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L32
  24. wrong-import-position:
    Import "from ansible.galaxy.user_agent import user_agent" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L33
  25. wrong-import-position:
    Import "from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L34
  26. wrong-import-position:
    Import "from ansible.module_utils.api import retry_with_delays_and_condition" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L35
  27. wrong-import-position:
    Import "from ansible.module_utils.api import generate_jittered_backoff" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L36
  28. wrong-import-position:
    Import "from ansible.module_utils.common.process import get_bin_path" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L37
  29. wrong-import-position:
    Import "from ansible.module_utils.common.sentinel import Sentinel" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L38
  30. wrong-import-position:
    Import "from ansible.module_utils.common.yaml import yaml_load" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L39
  31. wrong-import-position:
    Import "from ansible.module_utils.urls import open_url" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L40
  32. wrong-import-position:
    Import "from ansible.utils.display import Display" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L41
  33. wrong-import-position:
    Import "import ansible.constants as C" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/concrete_artifact_manager.py#L43
  34. wrong-import-position:
    Import "from ansible.galaxy.api import GalaxyAPI, GalaxyError" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/galaxy_api_proxy.py#L19
  35. wrong-import-position:
    Import "from ansible.module_utils.common.text.converters import to_text" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/galaxy_api_proxy.py#L20
  36. wrong-import-position:
    Import "from ansible.utils.display import Display" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/galaxy_api_proxy.py#L21
  37. wrong-import-position:
    Import "import ansible.constants as C" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L84
  38. wrong-import-position:
    Import "from ansible.errors import AnsibleError" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L85
  39. wrong-import-position:
    Import "from ansible.galaxy.api import GalaxyAPI" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L86
  40. wrong-import-position:
    Import "from ansible.galaxy.collection.concrete_artifact_manager import _consume_file, _download_file, _get_json_from_installed_dir, _get_meta_from_src_dir, _tarfile_extract" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L87
  41. wrong-import-position:
    Import "from ansible.galaxy.collection.galaxy_api_proxy import MultiGalaxyAPIProxy" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L94
  42. wrong-import-position:
    Import "from ansible.galaxy.collection.gpg import run_gpg_verify, parse_gpg_errors, get_signature_from_source, GPG_ERROR_MAP" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L95
  43. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.dataclasses import Candidate, Requirement, _is_installed_collection_dir" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L119
  44. wrong-import-position:
    Import "from ansible.galaxy.dependency_resolution.versioning import meets_requirements" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L122
  45. wrong-import-position:
    Import "from ansible.plugins.loader import get_all_plugin_loaders" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L123
  46. wrong-import-position:
    Import "from ansible.module_utils.common.file import S_IRWU_RG_RO, S_IRWXU_RXG_RXO, S_IXANY" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L124
  47. wrong-import-position:
    Import "from ansible.module_utils.common.sentinel import Sentinel" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L125
  48. wrong-import-position:
    Import "from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L126
  49. wrong-import-position:
    Import "from ansible.module_utils.common.collections import is_sequence" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L127
  50. wrong-import-position:
    Import "from ansible.module_utils.common.yaml import yaml_dump" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L128
  51. wrong-import-position:
    Import "from ansible.utils.collection_loader import AnsibleCollectionRef" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L129
  52. wrong-import-position:
    Import "from ansible.utils.display import Display" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L130
  53. wrong-import-position:
    Import "from ansible.utils.hashing import secure_hash, secure_hash_s" should be placed at the top of the module
    https://github.com/ansible/ansible/blob/85d20838ce8181738bcba98cffaf398b5ebc5e04/lib/ansible/galaxy/collection/__init__.py#L131

Effect on pandas:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "import textwrap" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/generic.py#L211
  2. wrong-import-position:
    Import "import textwrap" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/arrays/timedeltas.py#L86
  3. wrong-import-position:
    Import "from pandas.compat.numpy import function as nv" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/arrays/masked.py#L119
  4. wrong-import-position:
    Import "import numpy as np" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/_numba/executor.py#L13
  5. wrong-import-position:
    Import "from pandas.compat._optional import import_optional_dependency" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/_numba/executor.py#L15
  6. wrong-import-position:
    Import "from pandas.core.util.numba_ import jit_user_function" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/_numba/executor.py#L17
  7. wrong-import-position:
    Import "from pandas.core._numba.kernels.shared import is_monotonic_increasing" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/_numba/kernels/var_.py#L20
  8. wrong-import-position:
    Import "from pandas.core._numba.kernels.shared import is_monotonic_increasing" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/_numba/kernels/sum_.py#L24
  9. wrong-import-position:
    Import "from pandas.core.arrays.datetimelike import dtype_to_unit" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/window/rolling.py#L113
  10. wrong-import-position:
    Import "from pandas._libs.tslibs.dtypes import OFFSET_TO_PERIOD_FREQSTR" should be placed at the top of the module
    https://github.com/pandas-dev/pandas/blob/186c0815bf18edad20cc6b41388852c20a0352c1/pandas/core/indexes/datetimes.py#L80

Effect on pytest:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "import warnings" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/recwarn.py#L22
  2. wrong-import-position:
    Import "from _pytest.deprecated import check_ispytest" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/recwarn.py#L24
  3. wrong-import-position:
    Import "from _pytest.fixtures import fixture" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/recwarn.py#L25
  4. wrong-import-position:
    Import "from _pytest.outcomes import Exit" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/recwarn.py#L26
  5. wrong-import-position:
    Import "from _pytest.outcomes import fail" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/recwarn.py#L27
  6. wrong-import-position:
    Import "from _pytest.config import Config" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L34
  7. wrong-import-position:
    Import "from _pytest.config import hookimpl" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L35
  8. wrong-import-position:
    Import "from _pytest.config.argparsing import Parser" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L36
  9. wrong-import-position:
    Import "from _pytest.deprecated import check_ispytest" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L37
  10. wrong-import-position:
    Import "from _pytest.fixtures import fixture" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L38
  11. wrong-import-position:
    Import "from _pytest.fixtures import SubRequest" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L39
  12. wrong-import-position:
    Import "from _pytest.nodes import Collector" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L40
  13. wrong-import-position:
    Import "from _pytest.nodes import File" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L41
  14. wrong-import-position:
    Import "from _pytest.nodes import Item" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L42
  15. wrong-import-position:
    Import "from _pytest.reports import CollectReport" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/capture.py#L43
  16. wrong-import-position:
    Import "from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L40
  17. wrong-import-position:
    Import "from _pytest._io.saferepr import saferepr" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L41
  18. wrong-import-position:
    Import "from _pytest._io.saferepr import saferepr_unlimited" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L42
  19. wrong-import-position:
    Import "from _pytest._version import version" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L43
  20. wrong-import-position:
    Import "from _pytest.assertion import util" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L44
  21. wrong-import-position:
    Import "from _pytest.config import Config" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L45
  22. wrong-import-position:
    Import "from _pytest.fixtures import FixtureFunctionDefinition" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L46
  23. wrong-import-position:
    Import "from _pytest.main import Session" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L47
  24. wrong-import-position:
    Import "from _pytest.pathlib import absolutepath" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L48
  25. wrong-import-position:
    Import "from _pytest.pathlib import fnmatch_ex" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L49
  26. wrong-import-position:
    Import "from _pytest.stash import StashKey" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L50
  27. wrong-import-position:
    Import "from _pytest.assertion.util import format_explanation as _format_explanation" should be placed at the top of the module
    https://github.com/pytest-dev/pytest/blob/c287dd7147319bf76179633def108c4b5aa013e6/src/_pytest/assertion/rewrite.py#L54

Effect on poetry-core:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "from poetry.core.packages.package import Package" should be placed at the top of the module
    https://github.com/python-poetry/poetry-core/blob/129c2bc14825b00aefeaadf38fe911deac2634ff/src/poetry/core/packages/project_package.py#L16

Effect on sentry:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "from snuba_sdk import OrderBy" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/search/events/datasets/base.py#L10
  2. wrong-import-position:
    Import "from sentry.api.event_search import SearchFilter" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/search/events/datasets/base.py#L12
  3. wrong-import-position:
    Import "from sentry.exceptions import InvalidSearchQuery" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/search/events/datasets/base.py#L13
  4. wrong-import-position:
    Import "from sentry.search.events import fields" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/search/events/datasets/base.py#L14
  5. wrong-import-position:
    Import "from sentry.search.events.types import SelectType, WhereType" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/search/events/datasets/base.py#L15
  6. wrong-import-position:
    Import "from .manager import DeletionTaskManager" should be placed at the top of the module
    https://github.com/getsentry/sentry/blob/980ef9641dddae8f8f6b6771ae14e9bd7cc0a744/src/sentry/deletions/__init__.py#L10

Effect on black:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "from black.handle_ipynb_magics import jupyter_dependencies_are_installed" should be placed at the top of the module
    https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/files.py#L26
  2. wrong-import-position:
    Import "from black.mode import TargetVersion" should be placed at the top of the module
    https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/files.py#L27
  3. wrong-import-position:
    Import "from black.output import err" should be placed at the top of the module
    https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/files.py#L28
  4. wrong-import-position:
    Import "from black.report import Report" should be placed at the top of the module
    https://github.com/psf/black/blob/c3cc5a95d4f72e6ccc27ebae23344fce8cc70786/src/black/files.py#L29

Effect on home-assistant:
The following messages are no longer emitted:

Details
  1. wrong-import-position:
    Import "from .const import CONF_FALLBACK, CONF_REFRESH_TOKEN, CONST_OVERLAY_TADO_DEFAULT, DOMAIN, INSIDE_TEMPERATURE_MEASUREMENT, PRESET_AUTO, TEMP_OFFSET" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/tado/coordinator.py#L20
  2. wrong-import-position:
    Import "from .const import CONF_CONFIG_ENTRY, CONF_MEMO_TEXT, DOMAIN, SERVICE_CLEAR_CACHE, SERVICE_SCAN, SERVICE_SET_MEMO_TEXT, SERVICE_SYNC" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/velbus/services.py#L22
  3. wrong-import-position:
    Import "from .const import DOMAIN" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/renault/renault_vehicle.py#L25
  4. wrong-import-position:
    Import "from .coordinator import RenaultDataUpdateCoordinator" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/renault/renault_vehicle.py#L26
  5. wrong-import-position:
    Import "from time import time" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/renault/renault_hub.py#L30
  6. wrong-import-position:
    Import "from .const import CONF_KAMEREON_ACCOUNT_ID, COOLING_UPDATES_SECONDS, MAX_CALLS_PER_HOURS" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/renault/renault_hub.py#L32
  7. wrong-import-position:
    Import "from .renault_vehicle import COORDINATORS, RenaultVehicleProxy" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/renault/renault_hub.py#L37
  8. wrong-import-position:
    Import "from .const import DEBOUNCE_TIME, DEFAULT_SCAN_INTERVAL, OBSERVATION_VALID_TIME, RETRY_INTERVAL, RETRY_STOP, UPDATE_TIME_PERIOD" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/nws/coordinator.py#L23
  9. wrong-import-position:
    Import "from .const import ATTR_API_AIRPOLLUTION_AQI, ATTR_API_AIRPOLLUTION_CO, ATTR_API_AIRPOLLUTION_NH3, ATTR_API_AIRPOLLUTION_NO, ATTR_API_AIRPOLLUTION_NO2, ATTR_API_AIRPOLLUTION_O3, ATTR_API_AIRPOLLUTION_PM2_5, ATTR_API_AIRPOLLUTION_PM10, ATTR_API_AIRPOLLUTION_SO2, ATTR_API_CLOUDS, ATTR_API_CONDITION, ATTR_API_CURRENT, ATTR_API_DAILY_FORECAST, ATTR_API_DATETIME, ATTR_API_DEW_POINT, ATTR_API_FEELS_LIKE_TEMPERATURE, ATTR_API_FORECAST, ATTR_API_HOURLY_FORECAST, ATTR_API_HUMIDITY, ATTR_API_MINUTE_FORECAST, ATTR_API_PRECIPITATION, ATTR_API_PRECIPITATION_KIND, ATTR_API_PRESSURE, ATTR_API_RAIN, ATTR_API_SNOW, ATTR_API_TEMPERATURE, ATTR_API_UV_INDEX, ATTR_API_VISIBILITY_DISTANCE, ATTR_API_WEATHER, ATTR_API_WEATHER_CODE, ATTR_API_WIND_BEARING, ATTR_API_WIND_GUST, ATTR_API_WIND_SPEED, CONDITION_MAP, DOMAIN, OWM_MODE_AIRPOLLUTION, OWM_MODE_FREE_CURRENT, OWM_MODE_FREE_FORECAST, OWM_MODE_V30, WEATHER_CODE_SUNNY_OR_CLEAR_NIGHT" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/openweathermap/coordinator.py#L34
  10. wrong-import-position:
    Import "from .const import DOMAIN, OWM_MODE_V30" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/openweathermap/repairs.py#L16
  11. wrong-import-position:
    Import "from .utils import validate_api_key" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/openweathermap/repairs.py#L17
  12. wrong-import-position:
    Import "from .const import ACTIVE_UPDATE_RATE, SENSE_CONNECT_EXCEPTIONS, SENSE_TIMEOUT_EXCEPTIONS, SENSE_WEBSOCKET_EXCEPTIONS, TREND_UPDATE_RATE" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/sense/coordinator.py#L22
  13. wrong-import-position:
    Import "from .const import DOMAIN, REVERSE_DEVICE_UNIT_TO_HA" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/lg_thinq/coordinator.py#L20
  14. wrong-import-position:
    Import "from .const import CONF_KNX_KNXKEY_PASSWORD, DOMAIN, REPAIR_ISSUE_DATA_SECURE_GROUP_KEY, KNXConfigEntryData" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/knx/repairs.py#L22
  15. wrong-import-position:
    Import "from .storage.keyring import DEFAULT_KNX_KEYRING_FILENAME, save_uploaded_knxkeys_file" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/knx/repairs.py#L28
  16. wrong-import-position:
    Import "from .telegrams import SIGNAL_KNX_DATA_SECURE_ISSUE_TELEGRAM, TelegramDict" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/knx/repairs.py#L29
  17. wrong-import-position:
    Import "from .const import ATTR_RESOLUTION, DOMAIN" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/nordpool/services.py#L40
  18. wrong-import-position:
    Import "from .const import TessieStatus" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/tessie/coordinator.py#L23
  19. wrong-import-position:
    Import "from .const import DOMAIN, UPDATE_INTERVAL_ANALYTICS, UPDATE_INTERVAL_CONNECTION, UPDATE_INTERVAL_SETTINGS" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/nextdns/coordinator.py#L32
  20. wrong-import-position:
    Import "from .coordinator import OmadaClientsCoordinator, OmadaDevicesCoordinator, OmadaGatewayCoordinator, OmadaSwitchPortCoordinator" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/tplink_omada/controller.py#L15
  21. wrong-import-position:
    Import "from .const import DOMAIN, PLAYER_UPDATE_INTERVAL, SENSOR_UPDATE_INTERVAL, SIGNAL_PLAYER_REDISCOVERED, STATUS_API_TIMEOUT" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/squeezebox/coordinator.py#L22
  22. wrong-import-position:
    Import "from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES, LOGGER, UPDATE_INTERVAL" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/overkiz/coordinator.py#L32
  23. wrong-import-position:
    Import "from .const import ENERGY_HISTORY_FIELDS, LOGGER, TeslaFleetState" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/tesla_fleet/coordinator.py#L28
  24. wrong-import-position:
    Import "from .const import DEFAULT_AREAS, DOMAIN, STEP_ANALYTICS, STEP_CORE_CONFIG, STEP_INTEGRATION, STEP_USER, STEPS" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/onboarding/views.py#L30
  25. wrong-import-position:
    Import "from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, LOGGER, YALE_BASE_ERRORS" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/yale_smart_alarm/coordinator.py#L20
  26. wrong-import-position:
    Import "from .const import CONF_REMOVE_HOLIDAYS, DOMAIN, LOGGER" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/workday/util.py#L20
  27. wrong-import-position:
    Import "from .const import DOMAIN, TEMPLATE_ERRORS" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/mqtt/models.py#L37
  28. wrong-import-position:
    Import "from .util import read_fan_speed" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/systemmonitor/coordinator.py#L25
  29. wrong-import-position:
    Import "from .const import ENERGY_HISTORY_FIELDS, LOGGER" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/teslemetry/coordinator.py#L23
  30. wrong-import-position:
    Import "from .helpers import flatten" should be placed at the top of the module
    https://github.com/home-assistant/core/blob/7083a0fdb7c3f59fdfcc8ed99b6a39df11b679fa/homeassistant/components/teslemetry/coordinator.py#L24

This comment was generated for commit 771ac7c

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this really morphed from where we started, but looking at the primer that is a huge improvement.

@DanielNoord @Pierre-Sassoulas are you okay with where we took this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this file and the other blank one?

CONSTANT_C = 42
import json # pylint: disable=wrong-import-position

CONSTANT_D = "test" # pylint: disable=wrong-import-position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this here to test two pragmas in a row? Might be nice to comment that.


import base64 # [wrong-import-position]

try: # pylint: disable=wrong-import-position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples seem to follow different flows. I guess I'd expect to see a pattern of pragma, new statement, import statement. Just above this there is no new pragma before the while, with, and match examples, so I don't know what state is being tested.

Comment on lines +1 to +3
Allow ``wrong-import-position`` pragma on non-import lines to suppress following imports until the next non-import statement.

Closes #10589
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can update this to reflect the larger change we are making.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this LGTM pragma-handling wise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

disable=wrong-import-position applied to a statement that isn't an import fouls up recognition on later lines

5 participants