Skip to content

possibly-used-before-assignment doesn't understand negation of conditionals #9628

@chrisburr

Description

@chrisburr

Bug description

# pylint: disable=missing-module-docstring,invalid-name
a = bool(input("Enter something or nothing: "))

if a:
    b = "1234"

# pylint doesn't understand this one
if not a:
    pass
else:
    print(b)

# pylint does understand this one
if a:
    print(b)
else:
    pass

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:11:10: E0606: Possibly using variable 'b' before assignment (possibly-used-before-assignment)

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

Expected behavior

Pylint should understand both if a: ... and if not a: pass; else: ...

Pylint version

pylint 3.2.0
astroid 3.2.0
Python 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Labels

C: used-before-assignmentIssues related to 'used-before-assignment' checkDuplicate 🐫Duplicate of an already existing issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions