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

False negative used-before-assignment for self-referencing assignment in if-statement #6643

Closed
snordhausen opened this issue May 18, 2022 · 3 comments · Fixed by #6958
Closed
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code
Milestone

Comments

@snordhausen
Copy link

Bug description

The following code should trigger a used-before-assignment error from pylint, but it does not:

if 1 + 1 == 2:
    x = x + 1

When the if-statement is removed like

x = x + 1

the error is produced as expected.

Configuration

No response

Command used

python -m pylint foobar.py

Pylint output

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

Expected behavior

There should be a used-before-assignment error.

Pylint version

$ python -m pylint --version
pylint 2.13.9
astroid 2.11.5
Python 3.8.13 (default, Mar 31 2022, 14:08:37)

OS / Environment

Python interpreter was built by pyenv, on Ubuntu Linux 20.04

Additional dependencies

No response

@snordhausen snordhausen added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 18, 2022
@mbyrnepr2
Copy link
Member

mbyrnepr2 commented May 18, 2022

Duplicate of #4913 & #3229 & #1727?

@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 18, 2022
@Pierre-Sassoulas
Copy link
Member

Closing as duplicate of #1727 , thank you @mbyrnepr2 for triaging this !

@jacobtylerwalls
Copy link
Member

This one is also a leeetle different from #1727, because the problem usage is inside the conditional, not after it, so it doesn't depend on control flow--it's just totally wrong.

@jacobtylerwalls jacobtylerwalls added False Negative 🦋 No message is emitted but something is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check and removed Duplicate 🐫 Duplicate of an already existing issue labels May 19, 2022
@jacobtylerwalls jacobtylerwalls changed the title False negative used-before-assignment in if-statement False negative used-before-assignment for self-referencing assignment in if-statement May 19, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.15.0 milestone Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
4 participants