Commit e8cc17ab authored by Stefan Behnel's avatar Stefan Behnel

fix dir(obj) after implementing dir()

parent 4f05de43
...@@ -1757,21 +1757,26 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -1757,21 +1757,26 @@ class TransformBuiltinMethods(EnvTransform):
if entry: if entry:
# not the builtin # not the builtin
return node 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 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, items = [ ExprNodes.DictItemNode(pos,
key=ExprNodes.StringNode(pos, value=var), key=ExprNodes.StringNode(pos, value=var),
value=ExprNodes.NameNode(pos, name=var)) value=ExprNodes.NameNode(pos, name=var))
for var in lenv.entries ] for var in lenv.entries ]
return ExprNodes.DictNode(pos, key_value_pairs=items) return ExprNodes.DictNode(pos, key_value_pairs=items)
else: else:
items = [ ExprNodes.StringNode(pos, value=var) if len(node.args) > 1:
for var in lenv.entries ] 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) return ExprNodes.ListNode(pos, args=items)
def visit_SimpleCallNode(self, node): def visit_SimpleCallNode(self, node):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment