diff options
author | Géry Ogam <gery.ogam@gmail.com> | 2020-01-14 11:58:29 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2020-01-14 11:58:29 (GMT) |
commit | 1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d (patch) | |
tree | 1cecc3868d762cd3e1c2414520d954dfe05aea17 /Python | |
parent | 9af0e47b1705457bb6b327c197f2ec5737a1d8f6 (diff) | |
download | cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.zip cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.tar.gz cpython-1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d.tar.bz2 |
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')
-rw-r--r-- | Python/ceval.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 096645a..5e58658 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; |