alanjds / grumpy

**MOVED TO NEW MOTHER ORG `grumpyhome/grumpy`** Grumpy is a Python to Go source code transcompiler and runtime.
https://github.com/grumpyhome/grumpy
Apache License 2.0
16 stars 1 forks source link

Support tuple args in lambda #31

Open alanjds opened 6 years ago

alanjds commented 6 years ago

Per justinsaccount on HN:

$ make run c = {} top = sorted(c.items(), key=lambda (k,v): v) ^D Traceback (most recent call last): File "./tools/grumpc", line 102, in sys.exit(main(parser.parse_args())) File "./tools/grumpc", line 60, in main visitor.visit(mod) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit return visitor(node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/stmt.py", line 302, in visit_Module self._visit_each(node.body) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/stmt.py", line 632, in _visit_each self.visit(node) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit return visitor(node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/stin visit_Assign with self.expr_visitor.visit(node.value) as value: File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit return visitor(node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/expr_visitor.py", line 101, in visit_Call values.append((util.go_str(k.arg), self.visit(k.value))) File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit return visitor(node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/expr_visitor.py", line 246, in visit_Lambda return self.visit_function_inline(func_node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/expr_visitor.py", line 388, in visit_function_inline func_visitor = block.FunctionBlockVisitor(node) File "/Users/foo/src/grumpy/build/lib/python2.7/site-packages/grumpy/compiler/block.py", line 432, in init args = [a.id for a in node_args.args] AttributeError: 'Tuple' object has no attribute 'id'

alanjds commented 6 years ago

Comment by JustinAzoff Wednesday Jan 04, 2017 at 23:24 GMT


Can also reproduce it using tuple unpacking in function arguments (not very common, was removed in py3)

$ cat /tmp/foof.py
def func((a,b)):
    return b

mytuple = 1,2
print func(mytuple)
$ python /tmp/foof.py
2