pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.32k stars 1.14k forks source link

Pylint does not report undefined variable in if..else branch #7462

Closed iulian-birlica closed 2 years ago

iulian-birlica commented 2 years ago

Bug description

# pylint: disable=missing-docstring
import random
def function():
    if random.randrange(2) == 0:
        test = "something"
        print(test)
    else:
        print(test) # pylint should complain

Configuration

No response

Command used

pylint test.py

Pylint output

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

Expected behavior

Expected some kind of undefined variable warning.

Pylint version

pylint 2.15.2
astroid 2.12.9
Python 3.9.2 (default, Dec 16 2021, 12:56:11)
[GCC 6.3.0 20170516]

OS / Environment

No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 9.13 (stretch) Release: 9.13 Codename: stretch

Additional dependencies

No response

jacobtylerwalls commented 2 years ago

Thanks for the report. undefined-variable and used-before-assignment are almost synonymous. Duplicate of #1727