mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
gh-96751: Remove dead code from CALL_FUNCTION_EX
opcode (GH-96752)
This commit is contained in:
parent
8e9a37dde4
commit
e37ac5fbb6
3 changed files with 24 additions and 13 deletions
|
@ -382,6 +382,27 @@ Test a kwargs mapping with duplicated keys.
|
||||||
...
|
...
|
||||||
TypeError: test.test_extcall.g() got multiple values for keyword argument 'x'
|
TypeError: test.test_extcall.g() got multiple values for keyword argument 'x'
|
||||||
|
|
||||||
|
Call with dict subtype:
|
||||||
|
|
||||||
|
>>> class MyDict(dict):
|
||||||
|
... pass
|
||||||
|
|
||||||
|
>>> def s1(**kwargs):
|
||||||
|
... return kwargs
|
||||||
|
>>> def s2(*args, **kwargs):
|
||||||
|
... return (args, kwargs)
|
||||||
|
>>> def s3(*, n, **kwargs):
|
||||||
|
... return (n, kwargs)
|
||||||
|
|
||||||
|
>>> md = MyDict({'a': 1, 'b': 2})
|
||||||
|
>>> assert s1(**md) == {'a': 1, 'b': 2}
|
||||||
|
>>> assert s2(*(1, 2), **md) == ((1, 2), {'a': 1, 'b': 2})
|
||||||
|
>>> assert s3(**MyDict({'n': 1, 'b': 2})) == (1, {'b': 2})
|
||||||
|
>>> s3(**md)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
TypeError: s3() missing 1 required keyword-only argument: 'n'
|
||||||
|
|
||||||
Another helper function
|
Another helper function
|
||||||
|
|
||||||
>>> def f2(*a, **b):
|
>>> def f2(*a, **b):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove dead code from ``CALL_FUNCTION_EX`` opcode.
|
|
@ -4716,19 +4716,8 @@ handle_eval_breaker:
|
||||||
PyObject *func, *callargs, *kwargs = NULL, *result;
|
PyObject *func, *callargs, *kwargs = NULL, *result;
|
||||||
if (oparg & 0x01) {
|
if (oparg & 0x01) {
|
||||||
kwargs = POP();
|
kwargs = POP();
|
||||||
if (!PyDict_CheckExact(kwargs)) {
|
// DICT_MERGE is called before this opcode if there are kwargs.
|
||||||
PyObject *d = PyDict_New();
|
// It converts all dict subtypes in kwargs into regular dicts.
|
||||||
if (d == NULL)
|
|
||||||
goto error;
|
|
||||||
if (_PyDict_MergeEx(d, kwargs, 2) < 0) {
|
|
||||||
Py_DECREF(d);
|
|
||||||
format_kwargs_error(tstate, SECOND(), kwargs);
|
|
||||||
Py_DECREF(kwargs);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
Py_DECREF(kwargs);
|
|
||||||
kwargs = d;
|
|
||||||
}
|
|
||||||
assert(PyDict_CheckExact(kwargs));
|
assert(PyDict_CheckExact(kwargs));
|
||||||
}
|
}
|
||||||
callargs = POP();
|
callargs = POP();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue