You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that astroid seems perfectly able to infer that var_one is either the int 1 or the int 0, so the failure is in pylint failing to see that both of those values are unsubscriptable:
In [1]: import astroid
In [2]: src = open("pylinttest_short.py").read()
In [3]: tree = astroid.parse(src)
In [4]: tree.body[1].body[1].value.value
Out[4]: <Name.var_one l.12 at 0x10e2259e8>
In [5]: list(tree.body[1].body[1].value.value.infer())
Out[5]: [<Const.int l.6 at 0x10e2257b8>, <Const.int l.7 at 0x10e2257f0>]
In [6]: list(x.value for x in tree.body[1].body[1].value.value.infer())
Out[6]: [1, 0]
Not too surprisingly given that, the test case can be shortened to:
"""pylint test module"""
def test_one(param):
"""Should complain about var_one[0], but doesn't"""
var_one = 0
if param == 0:
var_one = 1
return var_one[0]
Thanks for reporting a bug! This is currently caused by our use of safe_infer, which returns None on multiple inferred object. I think we should allow safe_infer to return the inferred value when multiple values are sharing the same types, as in this case we can only infer integers from that function.
Steps to reproduce
pylint
on this code:Current behavior
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Expected behavior
E: 12,11: Value 'var_one' is unsubscriptable (unsubscriptable-object)
pylint --version output
Originally found on:
Also see identical behavior on this code with:
The text was updated successfully, but these errors were encountered: