Skip to content

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Sep 18, 2022

#170

> flake8 resources/test/fixtures/F402.py
resources/test/fixtures/F402.py:5:5: F402 import 'os' from line 1 shadowed by loop variable
resources/test/fixtures/F402.py:8:5: F402 import 'path' from line 2 shadowed by loop variable

> cargo run -- --no-cache resources/test/fixtures/F402.py
./resources/test/fixtures/F402.py:5:5: F402 import 'os' from line 1 shadowed by loop variable
./resources/test/fixtures/F402.py:8:5: F402 import 'path' from line 2 shadowed by loop variable

pass

for path in range(3):
pass
Copy link
Member

Choose a reason for hiding this comment

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

Flake8 has this check for self.differentForks(node, existing.source), which I think enables them to avoid flagging errors in cases like this:

if False:
    import typing
else:
    for typing in range(3):
        pass

(ruff raises F402 here, but Flake8 doesn't.)

It might be okay to have false positives for this rule in particular, but it seems like something we'll have to solve to support RedefinedWhileUnused and some others. differentForks requires that we store the parent stack for every binding, and then implement the differentForks logic.

Do you think that's worth doing here, as part of this PR? Or would you rather merge w/ these limitations?

(Either way, can we add an example using the if/else to F402.py, even if it has a TODO saying that we shouldn't be flagging that line?)

Copy link
Member

Choose a reason for hiding this comment

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

I guess pylint doesn't really do this, so maybe we should just not worry about it for now.

For example, pylint has a rule (W0621) around using a variable name that shadows a variable in the outer scope, and it does get triggered here:

if True:
    typing = 1
else:
    def f(typing):
        pass

Signed-off-by: harupy <hkawamura0130@gmail.com>
@charliermarsh charliermarsh merged commit 71d9b2a into astral-sh:main Sep 21, 2022
snowsignal pushed a commit that referenced this pull request Apr 29, 2024
Manual implementation of Debug trait for `SymbolKind` and `CompletionItemKind` as they are no longer Enums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants