# HG changeset patch # User Paul Boddie # Date 1490489419 -3600 # Node ID 7a592926e9e4e49695e40479d3305c951cc4c4e7 # Parent 172f844275ab9ccc85f5cf2600fe1480c6d5a1b0 Use item access methods directly instead of invoking operator functions. diff -r 172f844275ab -r 7a592926e9e4 common.py --- a/common.py Sun Mar 26 01:48:51 2017 +0100 +++ b/common.py Sun Mar 26 01:50:19 2017 +0100 @@ -650,22 +650,22 @@ def process_slice_node(self, n, expr=None): """ - Process the given slice node 'n' as an operator function invocation. + Process the given slice node 'n' as a method invocation. """ - if n.flags == "OP_ASSIGN": op = "setslice" - elif n.flags == "OP_DELETE": op = "delslice" - else: op = "getslice" + if n.flags == "OP_ASSIGN": op = "__setslice__" + elif n.flags == "OP_DELETE": op = "__delslice__" + else: op = "__getslice__" invocation = compiler.ast.CallFunc( - compiler.ast.Name("$op%s" % op), - [n.expr, n.lower or compiler.ast.Name("None"), n.upper or compiler.ast.Name("None")] + + compiler.ast.Getattr(n.expr, op), + [n.lower or compiler.ast.Name("None"), n.upper or compiler.ast.Name("None")] + (expr and [expr] or []) ) # Fix parse tree structure. - if op == "delslice": + if op == "__delslice__": invocation = compiler.ast.Discard(invocation) return self.process_structure_node(invocation) @@ -686,21 +686,21 @@ def process_subscript_node(self, n, expr=None): """ - Process the given subscript node 'n' as an operator function invocation. + Process the given subscript node 'n' as a method invocation. """ - if n.flags == "OP_ASSIGN": op = "setitem" - elif n.flags == "OP_DELETE": op = "delitem" - else: op = "getitem" + if n.flags == "OP_ASSIGN": op = "__setitem__" + elif n.flags == "OP_DELETE": op = "__delitem__" + else: op = "__getitem__" invocation = compiler.ast.CallFunc( - compiler.ast.Name("$op%s" % op), - [n.expr] + list(n.subs) + (expr and [expr] or []) + compiler.ast.Getattr(n.expr, op), + list(n.subs) + (expr and [expr] or []) ) # Fix parse tree structure. - if op == "delitem": + if op == "__delitem__": invocation = compiler.ast.Discard(invocation) return self.process_structure_node(invocation)