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.31k stars 1.14k forks source link

PyLint does not respect lazy evaluation strategies #1289

Open StephenWattam opened 7 years ago

StephenWattam commented 7 years ago

Steps to reproduce

  1. Run pylint with the following source:
arr = None
if arr and arr[0]:
    print("Never reached")

Current behavior

************* Module test
E:  3,11: Value 'arr' is unsubscriptable (unsubscriptable-object)

Expected behavior

No warning, or a warning about using this pattern at all. Maybe a warning about unreachable code in cases like this where arr is known to be falsy.

pylint --version output

pylint 1.6.4, 
astroid 1.4.9
Python 3.6.0 (default, Jan 16 2017, 12:12:55) 
[GCC 6.3.1 20170109]
degustaf commented 7 years ago

Unfortunately, pylint doesn't understand control flow yet, so it can't tell that the arr[0] isn't reached. These sorts of issues should be addressed after version 2.0 is released.