summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGéry Ogam <gery.ogam@gmail.com>2020-01-14 12:58:29 +0100
committerNick Coghlan <ncoghlan@gmail.com>2020-01-14 21:58:29 +1000
commit1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d (patch)
tree1cecc3868d762cd3e1c2414520d954dfe05aea17 /Python/ceval.c
parent9af0e47b1705457bb6b327c197f2ec5737a1d8f6 (diff)
downloadcpython-git-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.tar.gz
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
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 096645aeeb..5e586589e9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;