Skip to content

Commit 6e6fe8a

Browse files
committed
gh-96751: Remove dead code from CALL_FUNCTION_EX opcode
1 parent a36235d commit 6e6fe8a

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Lib/test/test_extcall.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,27 @@
382382
...
383383
TypeError: test.test_extcall.g() got multiple values for keyword argument 'x'
384384
385+
Call with dict subtype:
386+
387+
>>> class MyDict(dict):
388+
... pass
389+
390+
>>> def s1(**kwargs):
391+
... return kwargs
392+
>>> def s2(*args, **kwargs):
393+
... return (args, kwargs)
394+
>>> def s3(*, n, **kwargs):
395+
... return (n, kwargs)
396+
397+
>>> md = MyDict({'a': 1, 'b': 2})
398+
>>> assert s1(**md) == {'a': 1, 'b': 2}
399+
>>> assert s2(*(1, 2), **md) == ((1, 2), {'a': 1, 'b': 2})
400+
>>> assert s3(**MyDict({'n': 1, 'b': 2})) == (1, {'b': 2})
401+
>>> s3(**md)
402+
Traceback (most recent call last):
403+
...
404+
TypeError: s3() missing 1 required keyword-only argument: 'n'
405+
385406
Another helper function
386407
387408
>>> def f2(*a, **b):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove dead code from ``CALL_FUNCTION_EX`` opcode.

Python/ceval.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4719,19 +4719,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
47194719
PyObject *func, *callargs, *kwargs = NULL, *result;
47204720
if (oparg & 0x01) {
47214721
kwargs = POP();
4722-
if (!PyDict_CheckExact(kwargs)) {
4723-
PyObject *d = PyDict_New();
4724-
if (d == NULL)
4725-
goto error;
4726-
if (_PyDict_MergeEx(d, kwargs, 2) < 0) {
4727-
Py_DECREF(d);
4728-
format_kwargs_error(tstate, SECOND(), kwargs);
4729-
Py_DECREF(kwargs);
4730-
goto error;
4731-
}
4732-
Py_DECREF(kwargs);
4733-
kwargs = d;
4734-
}
4722+
// DICT_MERGE is called before this opcode.
47354723
assert(PyDict_CheckExact(kwargs));
47364724
}
47374725
callargs = POP();

0 commit comments

Comments
 (0)