Skip to content

redefined-outer-name no longer emitted in nested loops #6803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bolducfr opened this issue Jun 2, 2022 · 7 comments
Closed

redefined-outer-name no longer emitted in nested loops #6803

bolducfr opened this issue Jun 2, 2022 · 7 comments
Labels

Comments

@bolducfr
Copy link

bolducfr commented Jun 2, 2022

Bug description

The following Python code contains a redefined variable (instrument) in the inner loop:

def conflate(book):
    result = {}
    for instrument, trades in book.items():
        total = 0
        for qty, side1, side2, instrument in trades:
            if side1 != side2:
                total += qty
        result[instrument] = total
    return result

Pylint 2.13 correctly detects the error with the following message:

************* Module test
test.py:5:8: W0621: Redefining name 'instrument' from outer scope (line 3) (redefined-outer-name)

However, Pylint 2.14 fails to detect it.

Configuration

No response

Command used

pytlint test.py

Pylint output

Outputs nothing.

Expected behavior

Output:
************* Module test
test.py:5:8: W0621: Redefining name 'instrument' from outer scope (line 3) (redefined-outer-name)

Pylint version

2.14

OS / Environment

No response

Additional dependencies

No response

@bolducfr bolducfr added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 2, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report. This was an intentional design decision, because there were inconsistencies with how pylint treated overwriting loop variables. (We were special casing nested loops only.) To retain this check you need to enable the optional redefined-loop-name message. Ref #5649

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2022
@bolducfr
Copy link
Author

bolducfr commented Jun 2, 2022

How do I re-enable the check?

I tried adding:

--enable=redefined-loop-name

as well as:

--load-plugin==pylint.extensions.redefined_loop_name

and even:

--load-plugin==pylint.extensions.redefined_loop_name --enable=redefined-loop-name

but none of these work.

@Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas
Copy link
Member

I think the issue is that you're using load-plugin instead of --load-plugins. Don't you get a warning for this ?

@jacobtylerwalls
Copy link
Member

Yes, that's the issue. This command works:

pylint b.py --load-plugins=pylint.extensions.redefined_loop_name
************* Module b
b.py:5:8: W2901: Redefining 'instrument' from loop (line 3) (redefined-loop-name)

------------------------------------------------------------------
Your code has been rated at 8.89/10 (previous run: 0.00/10, +8.89)

@Pierre-Sassoulas @DanielNoord , no I don't see an error with --load-plugin. Is it an old name?

@jacobtylerwalls jacobtylerwalls changed the title Regression in 2.14 redefined-outer-name no longer emitted in nested loops Jun 2, 2022
@Pierre-Sassoulas
Copy link
Member

Opened #6810 to address this

@bolducfr
Copy link
Author

bolducfr commented Jun 2, 2022

I confirm I can again get the warning with the suggestion above. Thank you!

@jacobtylerwalls jacobtylerwalls added Question and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants