mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Fix SF bug #1167751, Argument genexp corner case
Incorrect code was generated for: foo(a = i for i in range(10)) This should have generated a SyntaxError. Fix the Grammar so it raises a SyntaxError and test it. I'm uncertain whether this should be backported. It makes something that was Syntactically valid invalid. However, the code would either be completely broken or do the wrong thing.
This commit is contained in:
		
							parent
							
								
									c0d5faa9b4
								
							
						
					
					
						commit
						37c0844b35
					
				
					 3 changed files with 30 additions and 10 deletions
				
			
		|  | @ -102,7 +102,7 @@ dictmaker: test ':' test (',' test ':' test)* [','] | ||||||
| classdef: 'class' NAME ['(' [testlist] ')'] ':' suite | classdef: 'class' NAME ['(' [testlist] ')'] ':' suite | ||||||
| 
 | 
 | ||||||
| arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) | arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) | ||||||
| argument: [test '='] test [gen_for] # Really [keyword '='] test | argument: test [gen_for] | test '=' test ['(' gen_for ')']  # Really [keyword '='] test | ||||||
| 
 | 
 | ||||||
| list_iter: list_for | list_if | list_iter: list_for | list_if | ||||||
| list_for: 'for' exprlist 'in' testlist_safe [list_iter] | list_for: 'for' exprlist 'in' testlist_safe [list_iter] | ||||||
|  |  | ||||||
|  | @ -82,6 +82,18 @@ | ||||||
|        ... |        ... | ||||||
|     SyntaxError: invalid syntax |     SyntaxError: invalid syntax | ||||||
| 
 | 
 | ||||||
|  | Verify that parenthesis are required when used as a keyword argument value | ||||||
|  | 
 | ||||||
|  |     >>> dict(a = i for i in xrange(10)) | ||||||
|  |     Traceback (most recent call last): | ||||||
|  |        ... | ||||||
|  |     SyntaxError: invalid syntax | ||||||
|  | 
 | ||||||
|  | Verify that parenthesis are required when used as a keyword argument value | ||||||
|  | 
 | ||||||
|  |     >>> dict(a = (i for i in xrange(10))) #doctest: +ELLIPSIS | ||||||
|  |     {'a': <generator object at ...>} | ||||||
|  | 
 | ||||||
| Verify early binding for the outermost for-expression | Verify early binding for the outermost for-expression | ||||||
| 
 | 
 | ||||||
|     >>> x=10 |     >>> x=10 | ||||||
|  | @ -125,12 +137,12 @@ | ||||||
|     >>> (y for y in (1,2)) = 10 |     >>> (y for y in (1,2)) = 10 | ||||||
|     Traceback (most recent call last): |     Traceback (most recent call last): | ||||||
|        ... |        ... | ||||||
|     SyntaxError: assignment to generator expression not possible (<doctest test.test_genexps.__test__.doctests[38]>, line 1) |     SyntaxError: assignment to generator expression not possible (<doctest test.test_genexps.__test__.doctests[40]>, line 1) | ||||||
| 
 | 
 | ||||||
|     >>> (y for y in (1,2)) += 10 |     >>> (y for y in (1,2)) += 10 | ||||||
|     Traceback (most recent call last): |     Traceback (most recent call last): | ||||||
|        ... |        ... | ||||||
|     SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_genexps.__test__.doctests[39]>, line 1) |     SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_genexps.__test__.doctests[41]>, line 1) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ########### Tests borrowed from or inspired by test_generators.py ############ | ########### Tests borrowed from or inspired by test_generators.py ############ | ||||||
|  |  | ||||||
|  | @ -1496,26 +1496,34 @@ static arc arcs_69_0[1] = { | ||||||
| 	{26, 1}, | 	{26, 1}, | ||||||
| }; | }; | ||||||
| static arc arcs_69_1[3] = { | static arc arcs_69_1[3] = { | ||||||
| 	{25, 2}, | 	{147, 2}, | ||||||
| 	{147, 3}, | 	{25, 3}, | ||||||
| 	{0, 1}, | 	{0, 1}, | ||||||
| }; | }; | ||||||
| static arc arcs_69_2[1] = { | static arc arcs_69_2[1] = { | ||||||
| 	{26, 4}, | 	{0, 2}, | ||||||
| }; | }; | ||||||
| static arc arcs_69_3[1] = { | static arc arcs_69_3[1] = { | ||||||
| 	{0, 3}, | 	{26, 4}, | ||||||
| }; | }; | ||||||
| static arc arcs_69_4[2] = { | static arc arcs_69_4[2] = { | ||||||
| 	{147, 3}, | 	{13, 5}, | ||||||
| 	{0, 4}, | 	{0, 4}, | ||||||
| }; | }; | ||||||
| static state states_69[5] = { | static arc arcs_69_5[1] = { | ||||||
|  | 	{147, 6}, | ||||||
|  | }; | ||||||
|  | static arc arcs_69_6[1] = { | ||||||
|  | 	{15, 2}, | ||||||
|  | }; | ||||||
|  | static state states_69[7] = { | ||||||
| 	{1, arcs_69_0}, | 	{1, arcs_69_0}, | ||||||
| 	{3, arcs_69_1}, | 	{3, arcs_69_1}, | ||||||
| 	{1, arcs_69_2}, | 	{1, arcs_69_2}, | ||||||
| 	{1, arcs_69_3}, | 	{1, arcs_69_3}, | ||||||
| 	{2, arcs_69_4}, | 	{2, arcs_69_4}, | ||||||
|  | 	{1, arcs_69_5}, | ||||||
|  | 	{1, arcs_69_6}, | ||||||
| }; | }; | ||||||
| static arc arcs_70_0[2] = { | static arc arcs_70_0[2] = { | ||||||
| 	{146, 1}, | 	{146, 1}, | ||||||
|  | @ -1806,7 +1814,7 @@ static dfa dfas[79] = { | ||||||
| 	 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\002\000"}, | 	 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\002\000"}, | ||||||
| 	{324, "arglist", 0, 8, states_68, | 	{324, "arglist", 0, 8, states_68, | ||||||
| 	 "\000\040\010\060\000\000\000\000\000\000\000\000\000\002\000\140\010\111\023\000\000"}, | 	 "\000\040\010\060\000\000\000\000\000\000\000\000\000\002\000\140\010\111\023\000\000"}, | ||||||
| 	{325, "argument", 0, 5, states_69, | 	{325, "argument", 0, 7, states_69, | ||||||
| 	 "\000\040\010\000\000\000\000\000\000\000\000\000\000\002\000\140\010\111\023\000\000"}, | 	 "\000\040\010\000\000\000\000\000\000\000\000\000\000\002\000\140\010\111\023\000\000"}, | ||||||
| 	{326, "list_iter", 0, 2, states_70, | 	{326, "list_iter", 0, 2, states_70, | ||||||
| 	 "\000\000\000\000\000\000\000\000\000\000\000\042\000\000\000\000\000\000\000\000\000"}, | 	 "\000\000\000\000\000\000\000\000\000\000\000\042\000\000\000\000\000\000\000\000\000"}, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Neal Norwitz
						Neal Norwitz