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
c9a71dd2
Unverified
Kaydet (Commit)
c9a71dd2
authored
Eyl 13, 2018
tarafından
Benjamin Peterson
Kaydeden (comit)
GitHub
Eyl 13, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
closes bpo-34641: Further restrict the LHS of keyword argument function call syntax. (GH-9212)
üst
6d9767fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
14 deletions
+50
-14
3.8.rst
Doc/whatsnew/3.8.rst
+4
-0
test_syntax.py
Lib/test/test_syntax.py
+3
-0
2018-09-11-23-12-33.bpo-34641.gFBCc9.rst
...ore and Builtins/2018-09-11-23-12-33.bpo-34641.gFBCc9.rst
+2
-0
ast.c
Python/ast.c
+41
-14
No files found.
Doc/whatsnew/3.8.rst
Dosyayı görüntüle @
c9a71dd2
...
...
@@ -94,6 +94,10 @@ Other Language Changes
* Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`.
(Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.)
* The syntax allowed for keyword names in function calls was further
restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was
never intended to permit more than a bare name on the left-hand side of a
keyword argument assignment term. See :issue:`34641`.
New Modules
===========
...
...
Lib/test/test_syntax.py
Dosyayı görüntüle @
c9a71dd2
...
...
@@ -269,6 +269,9 @@ SyntaxError: keyword can't be an expression
>>> f(x.y=1)
Traceback (most recent call last):
SyntaxError: keyword can't be an expression
>>> f((x)=2)
Traceback (most recent call last):
SyntaxError: keyword can't be an expression
More set_context():
...
...
Misc/NEWS.d/next/Core and Builtins/2018-09-11-23-12-33.bpo-34641.gFBCc9.rst
0 → 100644
Dosyayı görüntüle @
c9a71dd2
Further restrict the syntax of the left-hand side of keyword arguments in
function calls. In particular, ``f((keyword)=arg)`` is now disallowed.
Python/ast.c
Dosyayı görüntüle @
c9a71dd2
...
...
@@ -2815,29 +2815,56 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func, bool allowgen)
identifier
key
,
tmp
;
int
k
;
/* chch is test, but must be an identifier? */
e
=
ast_for_expr
(
c
,
chch
);
if
(
!
e
)
return
NULL
;
/* f(lambda x: x[0] = 3) ends up getting parsed with
* LHS test = lambda x: x[0], and RHS test = 3.
* SF bug 132313 points out that complaining about a keyword
* then is very confusing.
*/
if
(
e
->
kind
==
Lambda_kind
)
{
// To remain LL(1), the grammar accepts any test (basically, any
// expression) in the keyword slot of a call site. So, we need
// to manually enforce that the keyword is a NAME here.
static
const
int
name_tree
[]
=
{
test
,
or_test
,
and_test
,
not_test
,
comparison
,
expr
,
xor_expr
,
and_expr
,
shift_expr
,
arith_expr
,
term
,
factor
,
power
,
atom_expr
,
atom
,
0
,
};
node
*
expr_node
=
chch
;
for
(
int
i
=
0
;
name_tree
[
i
];
i
++
)
{
if
(
TYPE
(
expr_node
)
!=
name_tree
[
i
])
break
;
if
(
NCH
(
expr_node
)
!=
1
)
break
;
expr_node
=
CHILD
(
expr_node
,
0
);
}
if
(
TYPE
(
expr_node
)
==
lambdef
)
{
// f(lambda x: x[0] = 3) ends up getting parsed with LHS
// test = lambda x: x[0], and RHS test = 3. Issue #132313
// points out that complaining about a keyword then is very
// confusing.
ast_error
(
c
,
chch
,
"lambda cannot contain assignment"
);
return
NULL
;
}
else
if
(
e
->
kind
!=
Name_kind
)
{
else
if
(
TYPE
(
expr_node
)
!=
NAME
)
{
ast_error
(
c
,
chch
,
"keyword can't be an expression"
);
"keyword can't be an expression"
);
return
NULL
;
}
key
=
new_identifier
(
STR
(
expr_node
),
c
);
if
(
key
==
NULL
)
{
return
NULL
;
}
else
if
(
forbidden_name
(
c
,
e
->
v
.
Name
.
id
,
ch
,
1
))
{
if
(
forbidden_name
(
c
,
key
,
ch
ch
,
1
))
{
return
NULL
;
}
key
=
e
->
v
.
Name
.
id
;
for
(
k
=
0
;
k
<
nkeywords
;
k
++
)
{
tmp
=
((
keyword_ty
)
asdl_seq_GET
(
keywords
,
k
))
->
arg
;
if
(
tmp
&&
!
PyUnicode_Compare
(
tmp
,
key
))
{
...
...
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