Skip to content
Snippets Groups Projects
Commit 7e63f852 authored by Mike Bayer's avatar Mike Bayer
Browse files

- [bug] AST supporting now supports tuple-packed

  function arguments inside pure-python def
  or lambda expressions.  [ticket:201]
parent 8069ce33
No related branches found
No related tags found
No related merge requests found
0.7.3
- [bug] AST supporting now supports tuple-packed
function arguments inside pure-python def
or lambda expressions. [ticket:201]
0.7.2 0.7.2
- [bug] Fixed regression in 0.7.1 where AST - [bug] Fixed regression in 0.7.1 where AST
parsing for Py2.4 was broken. parsing for Py2.4 was broken.
......
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php # the MIT License: http://www.opensource.org/licenses/mit-license.php
__version__ = '0.7.2' __version__ = '0.7.3'
...@@ -112,6 +112,14 @@ if _ast: ...@@ -112,6 +112,14 @@ if _ast:
self._add_declared(node.name) self._add_declared(node.name)
self._visit_function(node, False) self._visit_function(node, False)
def _expand_tuples(self, args):
for arg in args:
if isinstance(arg, _ast.Tuple):
for n in arg.elts:
yield n
else:
yield arg
def _visit_function(self, node, islambda): def _visit_function(self, node, islambda):
# push function state onto stack. dont log any more # push function state onto stack. dont log any more
...@@ -125,7 +133,7 @@ if _ast: ...@@ -125,7 +133,7 @@ if _ast:
local_ident_stack = self.local_ident_stack local_ident_stack = self.local_ident_stack
self.local_ident_stack = local_ident_stack.union([ self.local_ident_stack = local_ident_stack.union([
arg_id(arg) for arg in node.args.args arg_id(arg) for arg in self._expand_tuples(node.args.args)
]) ])
if islambda: if islambda:
self.visit(node.body) self.visit(node.body)
...@@ -148,7 +156,7 @@ if _ast: ...@@ -148,7 +156,7 @@ if _ast:
def visit_Name(self, node): def visit_Name(self, node):
if isinstance(node.ctx, _ast.Store): if isinstance(node.ctx, _ast.Store):
# this is eqiuvalent to visit_AssName in # this is eqiuvalent to visit_AssName in
# compiler # compiler
self._add_declared(node.id) self._add_declared(node.id)
elif node.id not in reserved and node.id \ elif node.id not in reserved and node.id \
...@@ -261,6 +269,14 @@ else: ...@@ -261,6 +269,14 @@ else:
self._add_declared(node.name) self._add_declared(node.name)
self._visit_function(node, args) self._visit_function(node, args)
def _expand_tuples(self, args):
for arg in args:
if isinstance(arg, tuple):
for n in arg:
yield n
else:
yield arg
def _visit_function(self, node, args): def _visit_function(self, node, args):
# push function state onto stack. dont log any more # push function state onto stack. dont log any more
...@@ -274,7 +290,7 @@ else: ...@@ -274,7 +290,7 @@ else:
local_ident_stack = self.local_ident_stack local_ident_stack = self.local_ident_stack
self.local_ident_stack = local_ident_stack.union([ self.local_ident_stack = local_ident_stack.union([
arg for arg in node.argnames arg for arg in self._expand_tuples(node.argnames)
]) ])
for n in node.getChildNodes(): for n in node.getChildNodes():
......
...@@ -210,6 +210,17 @@ print(Bat) ...@@ -210,6 +210,17 @@ print(Bat)
eq_(parsed.declared_identifiers, set(['foo'])) eq_(parsed.declared_identifiers, set(['foo']))
eq_(parsed.undeclared_identifiers, set(['Bat'])) eq_(parsed.undeclared_identifiers, set(['Bat']))
def test_locate_identifiers_15(self):
code = """
def t1((x,y)):
return x+5, y+4
t2 = lambda (x,y):(x+5, y+4)
"""
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.declared_identifiers, set(['t1', 't2']))
eq_(parsed.undeclared_identifiers, set())
def test_no_global_imports(self): def test_no_global_imports(self):
code = """ code = """
from foo import * from foo import *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment