Skip to content

Commit c95a7ea

Browse files
committed
bpo-45045: Address code review
1 parent 696d0bd commit c95a7ea

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Python/ceval.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
846846
// - Don't cause key creation or resizing in dict subclasses like
847847
// collections.defaultdict that define __missing__ (or similar).
848848
_Py_IDENTIFIER(get);
849-
PyObject *get = _PyObject_GetAttrId(map, &PyId_get);
849+
PyObject *get_name = _PyUnicode_FromId(&PyId_get); // borrowed
850+
PyObject *get = NULL;
851+
int meth_found = _PyObject_GetMethod(map, get_name, &get);
850852
if (get == NULL) {
851853
goto fail;
852854
}
@@ -873,8 +875,14 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
873875
}
874876
goto fail;
875877
}
876-
PyObject *args[] = { key, dummy };
877-
PyObject *value = PyObject_Vectorcall(get, args, 2, NULL);
878+
PyObject *args[] = { map, key, dummy };
879+
PyObject *value = NULL;
880+
if (meth_found) {
881+
value = PyObject_Vectorcall(get, args, 3, NULL);
882+
}
883+
else {
884+
value = PyObject_Vectorcall(get, &args[1], 2, NULL);
885+
}
878886
if (value == NULL) {
879887
goto fail;
880888
}

0 commit comments

Comments
 (0)