Closed mabrowning closed 3 years ago
Yeah, I never really knew what the appropriate approach was here. If we switch your example around just a bit:
class MyClass:
def __init__(self):
self.value = None
def set(self):
self.value = Test()
def parse(self):
self.value.ParseFromString("blahblahblah")
Then node.expr.inferred()
also reports [<Const.NoneType l.7 at 0x...>, <Instance of .Test at 0x...>]
for the line self.value.ParseFromString(...)
. I think it's fairly reasonable to run the checker over types which have at one point been protobuf messages, short of simulating the whole universe.
node.expr.inferred()
can return multiple values, e.g. when a class member is initialized, then redefined:Before this PR,
pylint
produces:Because
node.expr.inferred()[0]
reflects the initial setting ofself.value = None
and returns (basically)NoneType
.I'm not sure the new logic is correct, but it visits all possible inferred types of the expression, and if any are a Protobuf class, enforce the protobuf specific constraints.