[Python-projects] Inference fails with augmented assignment
James Lingard
jchl at aristanetworks.com
Thu Nov 19 01:02:18 CET 2009
Inference doesn't seem to work correctly with augmented assignment. For
example, after:
x = 3
x += 5
print x
inference for the x node in the print statement gives the value 5, not 8.
I looked through the code to try to understand why this was happening. I
think I figured out how it occurs, but the code is complicated enough that
I'm not sure how it should be fixed. I suspect the bug is in the infer_ass
function (below). That function gets the list of assigned_stmts (i.e. the
RHS) of the augmented assignment, which is 5 in this case, and then simply
calls _infer_stmts, passing those assigned_stmts. I think infer_ass should
be enhanced to cover the case of an augmented assignment, by recursively
inferring x and returning a generator over all combinations of sums of the
inferred values of x and the inferred values of the RHS.
James.
def infer_ass(self, context=None):
"""infer a AssName/AssAttr: need to inspect the RHS part of the
assign node
"""
stmts = list(self.assigned_stmts(context=context))
return _infer_stmts(stmts, context)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.logilab.org/pipermail/python-projects/attachments/20091118/4c2c89e1/attachment.htm>
More information about the Python-Projects
mailing list