astroid
astroid copied to clipboard
no-member regression in 2.5.7
Steps to reproduce
Create a file names example.py
:
def S_OK(value=None):
return {'OK': True, 'Value': value}
class FooBar:
def __init__(self):
self.__initStatus = S_OK()
def check(self, result):
return result["Value"]
def load(self):
if not self.__initStatus['OK']:
return self.__initStatus
return S_OK((None, ["Hello"]))
def connect(self):
_, mylist = self.check(self.load())
mylist.append("world")
Current behavior
With astroid 2.5.7:
$ pylint -E example.py
************* Module example
example.py:19:4: E1101: Instance of 'str' has no 'append' member (no-member)
Expected behavior
With astroid 2.5.6:
$ pylint -E example.py
This appears to be a failure of inference for the return value of S_OK
in your example. There were some fixes around sequenc and mapping types if I remember correctly. Given
import astroid
good, fail = astroid.extract_node("""
def OK():
return {'constant': True}
def NOT_OK(value=None):
return {'constant': value}
def check(result):
return result["constant"]
check(OK()) #@
check(NOT_OK()) #@
""")
print(next(good.infer()))
print(next(fail.infer()))
astroid-2.5.6
:
Const.bool(value=True)
Uninferable
astroid-2.5.7
:
Const.bool(value=True)
Dict.dict(items=[ ( <Const.str l.6 at 0x7fe81093cdf0>,
<Name.value l.6 at 0x7fe8105ca550>)])