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 positive used-before-assignment #10195

Open
SpecLad opened this issue Jan 20, 2025 · 0 comments
Open

False positive used-before-assignment #10195

SpecLad opened this issue Jan 20, 2025 · 0 comments
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed

Comments

@SpecLad
Copy link

SpecLad commented Jan 20, 2025

Bug description

# pylint: disable=missing-docstring

def foobar(x):
    if x not in ["A"]:
        v = []

    if x == "B":
        print(v)
    elif x == "A":
        v = []
    else:
        raise RuntimeError(f'{x}')

Configuration

Command used

pylint pylint_repro.py

Pylint output

************* Module pylint_repro
pylint_repro.py:8:14: E0601: Using variable 'v' before assignment (used-before-assignment)

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

Expected behavior

Preferably no errors at all, but failing that, the error should be possibly-used-before-assignment, not used-before-assignment.

Pylint version

pylint 3.3.3
astroid 3.3.8
Python 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0]

OS / Environment

Ubuntu 24.04.

Additional dependencies

@SpecLad SpecLad added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 20, 2025
@Pierre-Sassoulas Pierre-Sassoulas added Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 23, 2025
@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Jan 29, 2025
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 Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed
Projects
None yet
Development

No branches or pull requests

3 participants