bpo-12022: Change error type for bad objects in "with" and "async wit… · python/cpython@20a8800 (original) (raw)
`@@ -82,7 +82,6 @@ static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyOb
`
82
82
`static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
`
83
83
`static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *,
`
84
84
`PyFrameObject *, const _Py_CODEUNIT *);
`
85
``
`-
static PyObject * special_lookup(PyThreadState *, PyObject *, _Py_Identifier *);
`
86
85
`static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
`
87
86
`static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
`
88
87
`static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int);
`
`@@ -3844,13 +3843,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
`
3844
3843
`_Py_IDENTIFIER(aenter);
`
3845
3844
`_Py_IDENTIFIER(aexit);
`
3846
3845
`PyObject *mgr = TOP();
`
3847
``
`-
PyObject *enter = special_lookup(tstate, mgr, &PyId___aenter__);
`
3848
3846
`PyObject *res;
`
``
3847
`+
PyObject *enter = PyObject_LookupSpecial(mgr, &PyId___aenter_);
`
3849
3848
`if (enter == NULL) {
`
``
3849
`+
if (!_PyErr_Occurred(tstate)) {
`
``
3850
`+
_PyErr_Format(tstate, PyExc_TypeError,
`
``
3851
`+
"'%.200s' object does not support the "
`
``
3852
`+
"asynchronous context manager protocol",
`
``
3853
`+
Py_TYPE(mgr)->tp_name);
`
``
3854
`+
}
`
3850
3855
` goto error;
`
3851
3856
` }
`
3852
``
`-
PyObject *exit = special_lookup(tstate, mgr, &PyId___aexit__);
`
``
3857
`+
PyObject *exit = PyObject_LookupSpecial(mgr, &PyId___aexit_);
`
3853
3858
`if (exit == NULL) {
`
``
3859
`+
if (!_PyErr_Occurred(tstate)) {
`
``
3860
`+
_PyErr_Format(tstate, PyExc_TypeError,
`
``
3861
`+
"'%.200s' object does not support the "
`
``
3862
`+
"asynchronous context manager protocol "
`
``
3863
`+
"(missed aexit method)",
`
``
3864
`+
Py_TYPE(mgr)->tp_name);
`
``
3865
`+
}
`
3854
3866
`Py_DECREF(enter);
`
3855
3867
` goto error;
`
3856
3868
` }
`
`@@ -3869,13 +3881,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
`
3869
3881
`_Py_IDENTIFIER(enter);
`
3870
3882
`_Py_IDENTIFIER(exit);
`
3871
3883
`PyObject *mgr = TOP();
`
3872
``
`-
PyObject *enter = special_lookup(tstate, mgr, &PyId___enter__);
`
3873
3884
`PyObject *res;
`
``
3885
`+
PyObject *enter = PyObject_LookupSpecial(mgr, &PyId___enter_);
`
3874
3886
`if (enter == NULL) {
`
``
3887
`+
if (!_PyErr_Occurred(tstate)) {
`
``
3888
`+
_PyErr_Format(tstate, PyExc_TypeError,
`
``
3889
`+
"'%.200s' object does not support the "
`
``
3890
`+
"context manager protocol",
`
``
3891
`+
Py_TYPE(mgr)->tp_name);
`
``
3892
`+
}
`
3875
3893
` goto error;
`
3876
3894
` }
`
3877
``
`-
PyObject *exit = special_lookup(tstate, mgr, &PyId___exit__);
`
``
3895
`+
PyObject *exit = PyObject_LookupSpecial(mgr, &PyId___exit_);
`
3878
3896
`if (exit == NULL) {
`
``
3897
`+
if (!_PyErr_Occurred(tstate)) {
`
``
3898
`+
_PyErr_Format(tstate, PyExc_TypeError,
`
``
3899
`+
"'%.200s' object does not support the "
`
``
3900
`+
"context manager protocol "
`
``
3901
`+
"(missed exit method)",
`
``
3902
`+
Py_TYPE(mgr)->tp_name);
`
``
3903
`+
}
`
3879
3904
`Py_DECREF(enter);
`
3880
3905
` goto error;
`
3881
3906
` }
`
`@@ -5110,19 +5135,6 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
`
5110
5135
`}
`
5111
5136
``
5112
5137
``
5113
``
`-
static PyObject *
`
5114
``
`-
special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id)
`
5115
``
`-
{
`
5116
``
`-
PyObject *res;
`
5117
``
`-
res = _PyObject_LookupSpecial(o, id);
`
5118
``
`-
if (res == NULL && !_PyErr_Occurred(tstate)) {
`
5119
``
`-
_PyErr_SetObject(tstate, PyExc_AttributeError, _PyUnicode_FromId(id));
`
5120
``
`-
return NULL;
`
5121
``
`-
}
`
5122
``
`-
return res;
`
5123
``
`-
}
`
5124
``
-
5125
``
-
5126
5138
`/* Logic for the raise statement (too complicated for inlining).
`
5127
5139
` This consumes a reference count to each of its arguments. */
`
5128
5140
`static int
`