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
9165f77d
Unverified
Kaydet (Commit)
9165f77d
authored
Kas 15, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Kas 15, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32012: Disallow trailing comma after genexpr without parenthesis. (#4382)
üst
3bda0222
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
13 deletions
+45
-13
3.7.rst
Doc/whatsnew/3.7.rst
+14
-0
test_syntax.py
Lib/test/test_syntax.py
+18
-3
2017-11-13-00-37-11.bpo-32012.Kprjqe.rst
...ore and Builtins/2017-11-13-00-37-11.bpo-32012.Kprjqe.rst
+4
-0
ast.c
Python/ast.c
+9
-10
No files found.
Doc/whatsnew/3.7.rst
Dosyayı görüntüle @
9165f77d
...
...
@@ -630,6 +630,20 @@ This section lists previously described changes and other bugfixes
that may require changes to your code.
Changes in Python behavior
--------------------------
* Due to an oversight, earlier Python versions erroneously accepted the
following syntax::
f(1 for x in [1],)
Python 3.7 now correctly raises a :exc:`SyntaxError`, as a generator
expression always needs to be directly inside a set of parentheses
and cannot have a comma on either side.
(Contributed by Serhiy Storchaka in :issue:`32012`.)
Changes in the Python API
-------------------------
...
...
Lib/test/test_syntax.py
Dosyayı görüntüle @
9165f77d
...
...
@@ -125,17 +125,32 @@ SyntaxError: invalid syntax
From ast_for_call():
>>> def f(it, *varargs):
>>> def f(it, *varargs
, **kwargs
):
... return list(it)
>>> L = range(10)
>>> f(x for x in L)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> f(x for x in L, 1)
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized if not sole argument
SyntaxError: Generator expression must be parenthesized
>>> f(x for x in L, y=1)
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f(x for x in L, *[])
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f(x for x in L, **{})
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f(L, x for x in L)
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f(x for x in L, y for y in L)
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized if not sole argument
SyntaxError: Generator expression must be parenthesized
>>> f(x for x in L,)
Traceback (most recent call last):
SyntaxError: Generator expression must be parenthesized
>>> f((x for x in L), 1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
...
...
Misc/NEWS.d/next/Core and Builtins/2017-11-13-00-37-11.bpo-32012.Kprjqe.rst
0 → 100644
Dosyayı görüntüle @
9165f77d
SyntaxError is now correctly raised when a generator expression without
parenthesis is passed as an argument, but followed by a trailing comma.
A generator expression always needs to be directly inside a set of parentheses
and cannot have a comma on either side.
Python/ast.c
Dosyayı görüntüle @
9165f77d
...
...
@@ -2712,7 +2712,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
argument: ( test [comp_for] | '*' test | test '=' test | '**' test )
*/
int
i
,
nargs
,
nkeywords
,
ngens
;
int
i
,
nargs
,
nkeywords
;
int
ndoublestars
;
asdl_seq
*
args
;
asdl_seq
*
keywords
;
...
...
@@ -2721,14 +2721,18 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
nargs
=
0
;
nkeywords
=
0
;
ngens
=
0
;
for
(
i
=
0
;
i
<
NCH
(
n
);
i
++
)
{
node
*
ch
=
CHILD
(
n
,
i
);
if
(
TYPE
(
ch
)
==
argument
)
{
if
(
NCH
(
ch
)
==
1
)
nargs
++
;
else
if
(
TYPE
(
CHILD
(
ch
,
1
))
==
comp_for
)
ngens
++
;
else
if
(
TYPE
(
CHILD
(
ch
,
1
))
==
comp_for
)
{
nargs
++
;
if
(
NCH
(
n
)
>
1
)
{
ast_error
(
c
,
ch
,
"Generator expression must be parenthesized"
);
return
NULL
;
}
}
else
if
(
TYPE
(
CHILD
(
ch
,
0
))
==
STAR
)
nargs
++
;
else
...
...
@@ -2736,13 +2740,8 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
nkeywords
++
;
}
}
if
(
ngens
>
1
||
(
ngens
&&
(
nargs
||
nkeywords
)))
{
ast_error
(
c
,
n
,
"Generator expression must be parenthesized "
"if not sole argument"
);
return
NULL
;
}
args
=
_Py_asdl_seq_new
(
nargs
+
ngens
,
c
->
c_arena
);
args
=
_Py_asdl_seq_new
(
nargs
,
c
->
c_arena
);
if
(
!
args
)
return
NULL
;
keywords
=
_Py_asdl_seq_new
(
nkeywords
,
c
->
c_arena
);
...
...
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