bpo-39048: Look up __aenter__ before __aexit__ in async with (GH-17609)

* Reorder the __aenter__ and __aexit__ checks for async with
* Add assertions for async with body being skipped
* Swap __aexit__ and __aenter__ loading in the documentation
This commit is contained in:
Géry Ogam 2020-01-14 12:58:29 +01:00 committed by Nick Coghlan
parent 9af0e47b17
commit 1d1b97ae64
5 changed files with 27 additions and 19 deletions

View file

@ -3230,20 +3230,21 @@ main_loop:
}
case TARGET(BEFORE_ASYNC_WITH): {
_Py_IDENTIFIER(__aexit__);
_Py_IDENTIFIER(__aenter__);
_Py_IDENTIFIER(__aexit__);
PyObject *mgr = TOP();
PyObject *exit = special_lookup(tstate, mgr, &PyId___aexit__),
*enter;
PyObject *enter = special_lookup(tstate, mgr, &PyId___aenter__);
PyObject *res;
if (exit == NULL)
if (enter == NULL) {
goto error;
}
PyObject *exit = special_lookup(tstate, mgr, &PyId___aexit__);
if (exit == NULL) {
Py_DECREF(enter);
goto error;
}
SET_TOP(exit);
enter = special_lookup(tstate, mgr, &PyId___aenter__);
Py_DECREF(mgr);
if (enter == NULL)
goto error;
res = _PyObject_CallNoArg(enter);
Py_DECREF(enter);
if (res == NULL)
@ -3264,8 +3265,8 @@ main_loop:
}
case TARGET(SETUP_WITH): {
_Py_IDENTIFIER(__exit__);
_Py_IDENTIFIER(__enter__);
_Py_IDENTIFIER(__exit__);
PyObject *mgr = TOP();
PyObject *enter = special_lookup(tstate, mgr, &PyId___enter__);
PyObject *res;