[issue27494] 2to3 parser failure caused by a comma after a generator expression

Serhiy Storchaka report at bugs.python.org
Tue Jul 31 09:00:26 EDT 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Sorry, I missed that you didn't receive a notification about creating of the reverting PR. I should announce this explicitly.

2to3 handles the old syntax, but a comma after a generator expression was not a valid old syntax. With your patch it accepted this syntax and produced invalid Python program.

$ ./python -m lib2to3 -w t9.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored t9.py
--- t9.py       (original)
+++ t9.py       (refactored)
@@ -1 +1 @@
-print(set(x for x in range(2),))
+print((set(x for x in list(range(2)),)))
RefactoringTool: Files that were modified:
RefactoringTool: t9.py
$ ./python t9.py 
  File "t9.py", line 1
    print((set(x for x in list(range(2)),)))
              ^
SyntaxError: Generator expression must be parenthesized

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27494>
_______________________________________


More information about the Python-bugs-list mailing list