From e8cc17ab7b15422748fdf4e133298da19423087e Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 14 Apr 2011 09:28:47 +0200 Subject: [PATCH] fix dir(obj) after implementing dir() --- Cython/Compiler/ParseTreeTransforms.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 251ca7dd..8f686735 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1757,21 +1757,26 @@ class TransformBuiltinMethods(EnvTransform): if entry: # not the builtin return node - max_args_count = {'dir': 1, 'locals': 0}[func_name] - if len(node.args) > max_args_count: - error(self.pos, "Builtin '%s()' called with wrong number of args, expected %d, got %d" % ( - func_name, max_args_count, len(node.args))) - return node pos = node.pos - if func_name =='locals': + if func_name == 'locals': + if len(node.args) > 0: + error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d" + % len(node.args)) + return node items = [ ExprNodes.DictItemNode(pos, key=ExprNodes.StringNode(pos, value=var), value=ExprNodes.NameNode(pos, name=var)) for var in lenv.entries ] return ExprNodes.DictNode(pos, key_value_pairs=items) else: - items = [ ExprNodes.StringNode(pos, value=var) - for var in lenv.entries ] + if len(node.args) > 1: + error(self.pos, "Builtin 'dir()' called with wrong number of args, expected 0-1, got %d" + % len(node.args)) + return node + elif len(node.args) == 1: + # optimised in Builtin.py + return node + items = [ ExprNodes.StringNode(pos, value=var) for var in lenv.entries ] return ExprNodes.ListNode(pos, args=items) def visit_SimpleCallNode(self, node): -- 2.26.2