pylint
pylint copied to clipboard
Unstable result of unsubscriptable-object error within if/elif/else block
Steps to reproduce
Create following files (or unzip sample.zip): test.py
a = None
for i in range(1, 5):
if i % 2:
a = "foo"
else:
a = a[1:]
test2.py
a = None
for i in range(1, 5):
if i % 2:
a = "foo"
if not i % 2:
a = a[1:]
test3.py
a = None
for i in range(1, 5):
if i % 2:
a = "foo"
elif not i % 2:
a = a[1:]
Then run:
pylint --disable=all --enable=typecheck test.py test2.py test3.py
Current behavior
No config file found, using default configuration
************* Module test3
E: 6, 6: Value 'a' is unsubscriptable (unsubscriptable-object)
Expected behavior
I think all of them should report the error, otherwise all of them should not. I'm not sure what is the difference between if/elif/else in pylint. Should I rewrite my code to avoid elif in this case?
A live example: https://github.com/eight04/pyAPNG/blob/bc5b9d9da666bbcdfa65ed3512134a9d143cb650/apng/init.py#L376
pylint --version output
D:\Dev\pyAPNG>pylint --version
Using config file D:\Dev\pyAPNG\.pylintrc
pylint 1.8.4,
astroid 1.6.1
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (In
tel)]