Skip to content
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

consider-using-augmented-assign false-positive on dictionaries #10032

Open
EugeneZelenko opened this issue Oct 18, 2024 · 0 comments
Open

consider-using-augmented-assign false-positive on dictionaries #10032

EugeneZelenko opened this issue Oct 18, 2024 · 0 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@EugeneZelenko
Copy link

EugeneZelenko commented Oct 18, 2024

Bug description

#!/usr/bin/env python3

values = {}
accumulated_values = {}
id = 0
for r in [1, 2, 3, 4, 5]:
    id += 1
    if id == 1:
        key = str(1)
        values[key]       = r
        accumulated_values[key] = r
    else:
        if key == '1':
            accumulated_values[key]  = values[key]
        else:
            previous = str(int(key) - 1)
            accumulated_values[key]  = accumulated_values[previous] + values[key]

        key           = str(1 + int(key))
        values[key]     = r
        previous = str(int(key) - 1)
        accumulated_values[key] = accumulated_values[previous] + values[key]
print(values)
print(accumulated_values)

Configuration

No response

Command used

pylint --enable-all-extensions --disable=all --enable=consider-using-augmented-assign consider-using-augmented-assign.py

Pylint output

************* Module consider-using-augmented-assign
consider-using-augmented-assign.py:22:8: R6104: Use '+=' to do an augmented assign directly (consider-using-augmented-assign)

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

Expected behavior

Warning should not be reported.

Pylint version

pylint 3.3.1
astroid 3.3.5
Python 3.12.7 (heads/main:466d8c8, Oct 15 2024, 03:59:42) [GCC 13.3.0]

OS / Environment

Rocky 8.10

Additional dependencies

No response

@EugeneZelenko EugeneZelenko added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

1 participant