New submission from Jeong-Min Lee:

lambda (x): x

should be transformed to 

lambda x: x

not
lambda x1: x1[0]

----------
components: Demos and Tools
files: 2to3_lambda_nontuple_param.diff
messages: 55654
nosy: falsetru, gvanrossum
severity: normal
status: open
title: [patch] 2to3, lambda with non-tuple argument inside parenthesis

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1107>
__________________________________
Index: tests/test_fixers.py
===================================================================
--- tests/test_fixers.py	(revision 57982)
+++ tests/test_fixers.py	(working copy)
@@ -1527,6 +1527,16 @@
         s = """lambda x: x + 5"""
         self.unchanged(s)
 
+    def test_lambda_single_nontuple_argument_inside_parenthesis(self):
+        b = """lambda (x): x"""
+        a = """lambda x: x"""
+        self.check(b, a)
+
+    def test_lambda_single_tuple_argument_inside_parenthesis(self):
+        b = """lambda (x,): x"""
+        a = """lambda x1: x1[0]"""
+        self.check(b, a)
+
     def test_lambda_simple(self):
         b = """lambda (x, y): x + f(y)"""
         a = """lambda x_y: x_y[0] + f(x_y[1])"""
Index: fixes/fix_tuple_params.py
===================================================================
--- fixes/fix_tuple_params.py	(revision 57982)
+++ fixes/fix_tuple_params.py	(working copy)
@@ -99,6 +99,12 @@
         body = results["body"]
 
         params = find_params(args)
+        if not isinstance(params, list):
+            new_param = Name(params)
+            new_param.set_prefix(args.get_prefix())
+            args.replace(new_param.clone())
+            return
+
         to_index = map_to_index(params)
         tup_name = self.new_name(tuple_name(params))
 
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to