Skip to content
Permalink
Browse files

fix for blocks taking a single unpacking argument. (e.g. { |(x, y) })

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Apr 23, 2013
1 parent 6ad2585 commit 336dbe23473bc31233b95963c8df36acf5155155
Showing with 19 additions and 3 deletions.
  1. +16 −0 tests/test_parser.py
  2. +3 −3 topaz/parser.py
@@ -1479,6 +1479,22 @@ def test_block(self, space):
)])
), 1)),
]))
assert space.parse("f { |(x, y)| }") == ast.Main(ast.Block([
ast.Statement(ast.Send(ast.Self(1), "f", [], ast.SendBlock(
[ast.Argument("0")],
None,
None,
ast.Block([
ast.Statement(ast.MultiAssignment(
ast.MultiAssignable([
ast.Variable("x", -1),
ast.Variable("y", -1),
]),
ast.Variable("0", 1),
))
]),
), 1))
]))

def test_lambda(self, space):
assert space.parse("->{}") == ast.Main(ast.Block([
@@ -163,7 +163,7 @@ def append_call_arg(self, box_arg, box):

def new_send_block(self, lineno, params, body):
stmts = body.getastlist() if body is not None else []
args = params.getargs() if params is not None else []
args = params.getargs(include_multi=True) if params is not None else []
splat = params.getsplatarg() if params is not None else None
block_arg = params.getblockarg() if params is not None else None

@@ -2933,8 +2933,8 @@ def __init__(self, args, splat_arg, block_arg):
self.splat_arg = splat_arg
self.block_arg = block_arg

def getargs(self):
if self.is_multiassignment():
def getargs(self, include_multi=False):
if self.is_multiassignment() and not include_multi:
return []
else:
return self.args

0 comments on commit 336dbe2

Please sign in to comment.
You can’t perform that action at this time.