Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
af810b35
Kaydet (Commit)
af810b35
authored
Eki 05, 2017
tarafından
Jakub Stasiak
Kaydeden (comit)
Benjamin Peterson
Eki 05, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
closes bpo-27494: Fix 2to3 handling of trailing comma after a generator expression (#3771)
üst
a8ed1174
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
10 deletions
+38
-10
Grammar.txt
Lib/lib2to3/Grammar.txt
+22
-3
fixer_util.py
Lib/lib2to3/fixer_util.py
+3
-3
fix_dict.py
Lib/lib2to3/fixes/fix_dict.py
+1
-1
fix_paren.py
Lib/lib2to3/fixes/fix_paren.py
+2
-2
fix_xrange.py
Lib/lib2to3/fixes/fix_xrange.py
+1
-1
test_parser.py
Lib/lib2to3/tests/test_parser.py
+7
-0
2017-09-26-01-43-17.bpo-27494.37QnaT.rst
...S.d/next/Library/2017-09-26-01-43-17.bpo-27494.37QnaT.rst
+2
-0
No files found.
Lib/lib2to3/Grammar.txt
Dosyayı görüntüle @
af810b35
...
...
@@ -130,8 +130,8 @@ atom: ('(' [yield_expr|testlist_gexp] ')' |
'{' [dictsetmaker] '}' |
'`' testlist1 '`' |
NAME | NUMBER | STRING+ | '.' '.' '.')
listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
listmaker: (test|star_expr) (
old_
comp_for | (',' (test|star_expr))* [','] )
testlist_gexp: (test|star_expr) (
old_
comp_for | (',' (test|star_expr))* [','] )
lambdef: 'lambda' [varargslist] ':' test
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [',']
...
...
@@ -161,9 +161,28 @@ argument: ( test [comp_for] |
star_expr )
comp_iter: comp_for | comp_if
comp_for: [ASYNC] 'for' exprlist 'in'
testlist_safe
[comp_iter]
comp_for: [ASYNC] 'for' exprlist 'in'
or_test
[comp_iter]
comp_if: 'if' old_test [comp_iter]
# 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.
#
# 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; we
# can parse code like set(x for x in [],).
#
# The syntax supported by this set of rules is not a valid Python 3 syntax,
# hence the prefix "old".
#
# 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]
testlist1: test (',' test)*
# not used in grammar, but may appear in "node" passed from Parser to Compiler
...
...
Lib/lib2to3/fixer_util.py
Dosyayı görüntüle @
af810b35
...
...
@@ -101,8 +101,8 @@ def ListComp(xp, fp, it, test=None):
test
.
prefix
=
" "
if_leaf
=
Leaf
(
token
.
NAME
,
"if"
)
if_leaf
.
prefix
=
" "
inner_args
.
append
(
Node
(
syms
.
comp_if
,
[
if_leaf
,
test
]))
inner
=
Node
(
syms
.
listmaker
,
[
xp
,
Node
(
syms
.
comp_for
,
inner_args
)])
inner_args
.
append
(
Node
(
syms
.
old_
comp_if
,
[
if_leaf
,
test
]))
inner
=
Node
(
syms
.
listmaker
,
[
xp
,
Node
(
syms
.
old_
comp_for
,
inner_args
)])
return
Node
(
syms
.
atom
,
[
Leaf
(
token
.
LBRACE
,
"["
),
inner
,
...
...
@@ -208,7 +208,7 @@ def attr_chain(obj, attr):
next
=
getattr
(
next
,
attr
)
p0
=
"""for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
|
old_
comp_for< 'for' any 'in' node=any any* >
"""
p1
=
"""
power<
...
...
Lib/lib2to3/fixes/fix_dict.py
Dosyayı görüntüle @
af810b35
...
...
@@ -83,7 +83,7 @@ class FixDict(fixer_base.BaseFix):
p1
=
patcomp
.
compile_pattern
(
P1
)
P2
=
"""for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
|
old_
comp_for< 'for' any 'in' node=any any* >
"""
p2
=
patcomp
.
compile_pattern
(
P2
)
...
...
Lib/lib2to3/fixes/fix_paren.py
Dosyayı görüntüle @
af810b35
...
...
@@ -15,7 +15,7 @@ class FixParen(fixer_base.BaseFix):
PATTERN
=
"""
atom< ('[' | '(')
(listmaker< any
comp_for<
old_
comp_for<
'for' NAME 'in'
target=testlist_safe< any (',' any)+ [',']
>
...
...
@@ -24,7 +24,7 @@ class FixParen(fixer_base.BaseFix):
>
|
testlist_gexp< any
comp_for<
old_
comp_for<
'for' NAME 'in'
target=testlist_safe< any (',' any)+ [',']
>
...
...
Lib/lib2to3/fixes/fix_xrange.py
Dosyayı görüntüle @
af810b35
...
...
@@ -55,7 +55,7 @@ class FixXrange(fixer_base.BaseFix):
p1
=
patcomp
.
compile_pattern
(
P1
)
P2
=
"""for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
|
old_
comp_for< 'for' any 'in' node=any any* >
| comparison< any 'in' node=any any*>
"""
p2
=
patcomp
.
compile_pattern
(
P2
)
...
...
Lib/lib2to3/tests/test_parser.py
Dosyayı görüntüle @
af810b35
...
...
@@ -459,6 +459,13 @@ class TestLiterals(GrammarTest):
self
.
validate
(
s
)
class
TestGeneratorExpressions
(
GrammarTest
):
def
test_trailing_comma_after_generator_expression_argument_works
(
self
):
# BPO issue 27494
self
.
validate
(
"set(x for x in [],)"
)
def
diff
(
fn
,
result
):
try
:
with
open
(
'@'
,
'w'
)
as
f
:
...
...
Misc/NEWS.d/next/Library/2017-09-26-01-43-17.bpo-27494.37QnaT.rst
0 → 100644
Dosyayı görüntüle @
af810b35
Make 2to3 accept a trailing comma in generator expressions. For example, ``set(x
for x in [],)`` is now allowed.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment