GeezerVison is showing github.com — gh-96751: Remove dead code from `CALL_FUNCTION_EX` opcode (GH-96752) · python/cpython@e37ac5f
File treeExpand file treeCollapse file tree Open diff view settings Misc/NEWS.d/next/Core and Builtins
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_extcall.py +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 382 | 382 | ... | 383 | 383 | TypeError: test.test_extcall.g() got multiple values for keyword argument 'x' | 384 | 384 |
| | 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 | +
| 385 | 406 | Another helper function | 386 | 407 |
| 387 | 408 | >>> def f2(*a, **b): | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Remove dead code from ``CALL_FUNCTION_EX`` opcode. |
Collapse file Copy file name to clipboardExpand all lines: Python/ceval.c +2-13Lines changed: 2 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4716,19 +4716,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int | 4716 | 4716 | PyObject *func, *callargs, *kwargs = NULL, *result; | 4717 | 4717 | if (oparg & 0x01) { | 4718 | 4718 | kwargs = POP(); | 4719 | | - if (!PyDict_CheckExact(kwargs)) { | 4720 | | - PyObject *d = PyDict_New(); | 4721 | | - if (d == NULL) | 4722 | | - goto error; | 4723 | | - if (_PyDict_MergeEx(d, kwargs, 2) < 0) { | 4724 | | - Py_DECREF(d); | 4725 | | - format_kwargs_error(tstate, SECOND(), kwargs); | 4726 | | - Py_DECREF(kwargs); | 4727 | | - goto error; | 4728 | | - } | 4729 | | - Py_DECREF(kwargs); | 4730 | | - kwargs = d; | 4731 | | - } | | 4719 | + // DICT_MERGE is called before this opcode if there are kwargs. | | 4720 | + // It converts all dict subtypes in kwargs into regular dicts. | 4732 | 4721 | assert(PyDict_CheckExact(kwargs)); | 4733 | 4722 | } | 4734 | 4723 | callargs = POP(); | |
|