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)
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to