Skip to content

False positive: possibly-used-before-assignment doesn't understand and-ed contions #9662

Open
@skirpichev

Description

@skirpichev

Bug description

# pylint: disable=missing-module-docstring,invalid-name
a = bool(input())
b = bool(input())

if a:
    c = 123

if a and b:
    print(c)  # report possibly-used-before-assignment

if a:
    c += 1  # ok

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:9:10: E0601: Using variable 'c' before assignment (used-before-assignment)

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

Expected behavior

No errors

Pylint version

pylint 3.2.2
astroid 3.2.2
Python 3.11.3+ (heads/3.11:9fbb614c4e, Apr 29 2023, 14:18:05) [GCC 10.2.1 20210110]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeHigh effort 🏋Difficult solution or problem to solveNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions