Skip to content

Commit a864e5a

Browse files
committed
Delegate attributes instead of using proxy methods.
1 parent e8d7848 commit a864e5a

1 file changed

Lines changed: 9 additions & 35 deletions

File tree

Objects/genobject.c

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,39 +2682,13 @@ static PyAsyncMethods async_gen_yield_from_as_async = {
26822682
.am_send = async_gen_yield_from_send
26832683
};
26842684

2685-
#define AGYF_PROXY_METHOD(name, result_value) \
2686-
static PyObject * \
2687-
async_gen_yield_from_ ## name ## _method(PyObject *op, PyObject *args, PyObject *keywords) \
2688-
{ \
2689-
assert(op != NULL); \
2690-
_PyAsyncGenYieldFrom *self = _PyAsyncGenYieldFrom_CAST(op); \
2691-
PyObject *method; \
2692-
if (PyObject_GetOptionalAttr(self->agyf_iterator, &_Py_ID(name), &method) < 0) { \
2693-
return NULL; \
2694-
} \
2695-
if (method == NULL) { \
2696-
Py_RETURN_NONE; \
2697-
} \
2698-
PyObject *result = PyObject_Call(method, args, keywords); \
2699-
Py_DECREF(method); \
2700-
if (result == NULL) { \
2701-
return NULL; \
2702-
} \
2703-
return result_value; \
2704-
}
2705-
2706-
2707-
2708-
AGYF_PROXY_METHOD(send, _PyAsyncGenValueWrapperNew(_PyThreadState_GET(), result))
2709-
AGYF_PROXY_METHOD(throw, result)
2710-
AGYF_PROXY_METHOD(close, result)
2711-
2712-
static PyMethodDef async_gen_yield_from_methods[] = {
2713-
{"send", (PyCFunction)async_gen_yield_from_send_method, METH_VARARGS | METH_KEYWORDS},
2714-
{"throw", (PyCFunction)async_gen_yield_from_throw_method, METH_VARARGS | METH_KEYWORDS},
2715-
{"close", (PyCFunction)async_gen_yield_from_close_method, METH_VARARGS | METH_KEYWORDS},
2716-
{0}
2717-
};
2685+
static PyObject *
2686+
async_gen_yield_from_get_attr(PyObject *op, PyObject *attribute)
2687+
{
2688+
assert(op != NULL);
2689+
_PyAsyncGenYieldFrom *self = _PyAsyncGenYieldFrom_CAST(op);
2690+
return PyObject_GenericGetAttr(self->agyf_iterator, attribute);
2691+
}
27182692

27192693
PyTypeObject _PyAsyncGenYieldFrom_Type = {
27202694
PyVarObject_HEAD_INIT(&PyType_Type, 0)
@@ -2734,7 +2708,7 @@ PyTypeObject _PyAsyncGenYieldFrom_Type = {
27342708
0, /* tp_hash */
27352709
0, /* tp_call */
27362710
0, /* tp_str */
2737-
PyObject_GenericGetAttr, /* tp_getattro */
2711+
async_gen_yield_from_get_attr, /* tp_getattro */
27382712
0, /* tp_setattro */
27392713
0, /* tp_as_buffer */
27402714
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
@@ -2745,7 +2719,7 @@ PyTypeObject _PyAsyncGenYieldFrom_Type = {
27452719
0, /* tp_weaklistoffset */
27462720
PyObject_SelfIter, /* tp_iter */
27472721
async_gen_yield_from_iternext, /* tp_iternext */
2748-
async_gen_yield_from_methods, /* tp_methods */
2722+
0, /* tp_methods */
27492723
0, /* tp_members */
27502724
0, /* tp_getset */
27512725
0, /* tp_base */

0 commit comments

Comments
 (0)