Skip to content

False positive used-before-assignment when usage and assignment guarded by the same test in different statements #8167

@tvandeveenzepp

Description

@tvandeveenzepp

Bug description

The used-before-assignment check reports false positive for using the same variable inside multiple if __name__ == '__main__' statements.

# pylint: disable=missing-docstring

if __name__ == '__main__':
    X = 1

if __name__ == '__main__':
    print(X)

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:7:10: E0601: Using variable 'X' before assignment (used-before-assignment)

-----------------------------------
Your code has been rated at 0.00/10

Expected behavior

No error.

Pylint version

pylint 2.16.0
astroid 2.14.1
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Labels

Blocker 🙅Blocks the next releaseC: used-before-assignmentIssues related to 'used-before-assignment' checkControl flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeHigh priorityIssue with more than 10 reactionsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions