Skip to content

False positive used-before-assignment #10195

Open
@SpecLad

Description

@SpecLad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkControl flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds design proposal 🔒This is a huge feature, some discussion should happen before a PR is proposed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions