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
f1ec3cef
Unverified
Kaydet (Commit)
f1ec3cef
authored
Ock 12, 2019
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Ock 12, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-35634: Raise an error when first passed kwargs contains duplicated keys. (GH-11438)
üst
58159ef8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
48 deletions
+94
-48
test_extcall.py
Lib/test/test_extcall.py
+46
-0
2019-01-05-18-39-49.bpo-35634.nVP_gs.rst
...ore and Builtins/2019-01-05-18-39-49.bpo-35634.nVP_gs.rst
+3
-0
ceval.c
Python/ceval.c
+45
-48
No files found.
Lib/test/test_extcall.py
Dosyayı görüntüle @
f1ec3cef
...
@@ -316,6 +316,52 @@ not function
...
@@ -316,6 +316,52 @@ not function
...
...
TypeError: dir() got multiple values for keyword argument 'b'
TypeError: dir() got multiple values for keyword argument 'b'
Test a kwargs mapping with duplicated keys.
>>> from collections.abc import Mapping
>>> class MultiDict(Mapping):
... def __init__(self, items):
... self._items = items
...
... def __iter__(self):
... return (k for k, v in self._items)
...
... def __getitem__(self, key):
... for k, v in self._items:
... if k == key:
... return v
... raise KeyError(key)
...
... def __len__(self):
... return len(self._items)
...
... def keys(self):
... return [k for k, v in self._items]
...
... def values(self):
... return [v for k, v in self._items]
...
... def items(self):
... return [(k, v) for k, v in self._items]
...
>>> g(**MultiDict([('x', 1), ('y', 2)]))
1 () {'y': 2}
>>> g(**MultiDict([('x', 1), ('x', 2)]))
Traceback (most recent call last):
...
TypeError: g() got multiple values for keyword argument 'x'
>>> g(a=3, **MultiDict([('x', 1), ('x', 2)]))
Traceback (most recent call last):
...
TypeError: g() got multiple values for keyword argument 'x'
>>> g(**MultiDict([('a', 3)]), **MultiDict([('x', 1), ('x', 2)]))
Traceback (most recent call last):
...
TypeError: g() got multiple values for keyword argument 'x'
Another helper function
Another helper function
>>> def f2(*a, **b):
>>> def f2(*a, **b):
...
...
Misc/NEWS.d/next/Core and Builtins/2019-01-05-18-39-49.bpo-35634.nVP_gs.rst
0 → 100644
Dosyayı görüntüle @
f1ec3cef
``func(**kwargs)`` will now raise an error when ``kwargs`` is a mapping
containing multiple entries with the same key. An error was already raised
when other keyword arguments are passed before ``**kwargs`` since Python 3.6.
Python/ceval.c
Dosyayı görüntüle @
f1ec3cef
...
@@ -70,7 +70,7 @@ static PyObject * unicode_concatenate(PyObject *, PyObject *,
...
@@ -70,7 +70,7 @@ static PyObject * unicode_concatenate(PyObject *, PyObject *,
PyFrameObject
*
,
const
_Py_CODEUNIT
*
);
PyFrameObject
*
,
const
_Py_CODEUNIT
*
);
static
PyObject
*
special_lookup
(
PyObject
*
,
_Py_Identifier
*
);
static
PyObject
*
special_lookup
(
PyObject
*
,
_Py_Identifier
*
);
static
int
check_args_iterable
(
PyObject
*
func
,
PyObject
*
vararg
);
static
int
check_args_iterable
(
PyObject
*
func
,
PyObject
*
vararg
);
static
void
format_kwargs_
mapping_
error
(
PyObject
*
func
,
PyObject
*
kwargs
);
static
void
format_kwargs_error
(
PyObject
*
func
,
PyObject
*
kwargs
);
static
void
format_awaitable_error
(
PyTypeObject
*
,
int
);
static
void
format_awaitable_error
(
PyTypeObject
*
,
int
);
#define NAME_ERROR_MSG \
#define NAME_ERROR_MSG \
...
@@ -2660,37 +2660,8 @@ main_loop:
...
@@ -2660,37 +2660,8 @@ main_loop:
for
(
i
=
oparg
;
i
>
0
;
i
--
)
{
for
(
i
=
oparg
;
i
>
0
;
i
--
)
{
PyObject
*
arg
=
PEEK
(
i
);
PyObject
*
arg
=
PEEK
(
i
);
if
(
_PyDict_MergeEx
(
sum
,
arg
,
2
)
<
0
)
{
if
(
_PyDict_MergeEx
(
sum
,
arg
,
2
)
<
0
)
{
PyObject
*
func
=
PEEK
(
2
+
oparg
);
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
format_kwargs_mapping_error
(
func
,
arg
);
}
else
if
(
PyErr_ExceptionMatches
(
PyExc_KeyError
))
{
PyObject
*
exc
,
*
val
,
*
tb
;
PyErr_Fetch
(
&
exc
,
&
val
,
&
tb
);
if
(
val
&&
PyTuple_Check
(
val
)
&&
PyTuple_GET_SIZE
(
val
)
==
1
)
{
PyObject
*
key
=
PyTuple_GET_ITEM
(
val
,
0
);
if
(
!
PyUnicode_Check
(
key
))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s keywords must be strings"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
));
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s got multiple "
"values for keyword argument '%U'"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
key
);
}
Py_XDECREF
(
exc
);
Py_XDECREF
(
val
);
Py_XDECREF
(
tb
);
}
else
{
PyErr_Restore
(
exc
,
val
,
tb
);
}
}
Py_DECREF
(
sum
);
Py_DECREF
(
sum
);
format_kwargs_error
(
PEEK
(
2
+
oparg
),
arg
);
goto
error
;
goto
error
;
}
}
}
}
...
@@ -3286,17 +3257,9 @@ main_loop:
...
@@ -3286,17 +3257,9 @@ main_loop:
PyObject
*
d
=
PyDict_New
();
PyObject
*
d
=
PyDict_New
();
if
(
d
==
NULL
)
if
(
d
==
NULL
)
goto
error
;
goto
error
;
if
(
PyDict_Update
(
d
,
kwargs
)
!=
0
)
{
if
(
_PyDict_MergeEx
(
d
,
kwargs
,
2
)
<
0
)
{
Py_DECREF
(
d
);
Py_DECREF
(
d
);
/* PyDict_Update raises attribute
format_kwargs_error
(
SECOND
(),
kwargs
);
* error (percolated from an attempt
* to get 'keys' attribute) instead of
* a type error if its second argument
* is not a mapping.
*/
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
format_kwargs_mapping_error
(
SECOND
(),
kwargs
);
}
Py_DECREF
(
kwargs
);
Py_DECREF
(
kwargs
);
goto
error
;
goto
error
;
}
}
...
@@ -5063,14 +5026,48 @@ check_args_iterable(PyObject *func, PyObject *args)
...
@@ -5063,14 +5026,48 @@ check_args_iterable(PyObject *func, PyObject *args)
}
}
static
void
static
void
format_kwargs_
mapping_
error
(
PyObject
*
func
,
PyObject
*
kwargs
)
format_kwargs_error
(
PyObject
*
func
,
PyObject
*
kwargs
)
{
{
PyErr_Format
(
PyExc_TypeError
,
/* _PyDict_MergeEx raises attribute
"%.200s%.200s argument after ** "
* error (percolated from an attempt
"must be a mapping, not %.200s"
,
* to get 'keys' attribute) instead of
PyEval_GetFuncName
(
func
),
* a type error if its second argument
PyEval_GetFuncDesc
(
func
),
* is not a mapping.
kwargs
->
ob_type
->
tp_name
);
*/
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s argument after ** "
"must be a mapping, not %.200s"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
kwargs
->
ob_type
->
tp_name
);
}
else
if
(
PyErr_ExceptionMatches
(
PyExc_KeyError
))
{
PyObject
*
exc
,
*
val
,
*
tb
;
PyErr_Fetch
(
&
exc
,
&
val
,
&
tb
);
if
(
val
&&
PyTuple_Check
(
val
)
&&
PyTuple_GET_SIZE
(
val
)
==
1
)
{
PyObject
*
key
=
PyTuple_GET_ITEM
(
val
,
0
);
if
(
!
PyUnicode_Check
(
key
))
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s keywords must be strings"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
));
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%.200s got multiple "
"values for keyword argument '%U'"
,
PyEval_GetFuncName
(
func
),
PyEval_GetFuncDesc
(
func
),
key
);
}
Py_XDECREF
(
exc
);
Py_XDECREF
(
val
);
Py_XDECREF
(
tb
);
}
else
{
PyErr_Restore
(
exc
,
val
,
tb
);
}
}
}
}
static
void
static
void
...
...
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