Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-27494: Fix 2to3 handling of trailing comma after a generator expression #3771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
reword
  • Loading branch information
benjaminp committed Oct 5, 2017
commit 07560411f34dfd464b1d3b0874401288c1a8b60c
20 changes: 10 additions & 10 deletions 20 Lib/lib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,21 @@ comp_iter: comp_for | comp_if
comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
comp_if: 'if' old_test [comp_iter]

# See note above regarding testlist_safe to see why testlist_safe is
# necessary. Unfortunately we can't use it indiscriminately in all derivations
# using comp_for-like pattern because testlist_safe derivation contains
# comma which clashes with trailing comma in arglist.
# As noted above, testlist_safe extends the syntax allowed in list
# comprehensions and generators. We can't use it indiscriminately in all
# derivations using a comp_for-like pattern because the testlist_safe derivation
# contains comma which clashes with trailing comma in arglist.
#
# The above was an issue because the parser would not follow the correct derivation
# This was an issue because the parser would not follow the correct derivation
# when parsing syntactically valid Python code. Since testlist_safe was created
# specifically to handle list comprehensions and generator expressions enclosed
# with parentheses it's safe to only use it in those. That avoids the issue
# mentioned above and we can parse code like set(x for x in [],).
# with parentheses, it's safe to only use it in those. That avoids the issue; we
# can parse code like set(x for x in [],).
#
# Note that the syntax supported by this set of rules is not a valid Python 3
# syntax, hence the prefix "old".
# The syntax supported by this set of rules is not a valid Python 3 syntax,
# hence the prefix "old".
#
# See the bug report: http://bugs.python.org/issue27494
# See https://bugs.python.org/issue27494
old_comp_iter: old_comp_for | old_comp_if
old_comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [old_comp_iter]
old_comp_if: 'if' old_test [old_comp_iter]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2to3 doesn't choke on a trailing comma following a generator expression
anymore.
Make 2to3 accept a trailing comma in generator expressions. For example, ``set(x
for x in [],)`` is now allowed.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.