CPython . , , promises Python .
, , , .
a __set__ __delete__, Python, CPython slot_tp_descr_set, C, (, C .)
static int
slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value)
{
PyObject *res;
_Py_IDENTIFIER(__delete__);
_Py_IDENTIFIER(__set__);
if (value == NULL)
res = call_method(self, &PyId___delete__, "(O)", target);
else
res = call_method(self, &PyId___set__, "(OO)", target, value);
if (res == NULL)
return -1;
Py_DECREF(res);
return 0;
}
call_method, __getattribute__, __getattr__ dict, , .
, - MyClass.d, , __set__ __delete__ MyClass.d . , Python, , Python Descriptor __set__ __delete__.
a __get__, Python, CPython slot_tp_descr_get, -.
static PyObject *
slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject *get;
_Py_IDENTIFIER(__get__);
get = _PyType_LookupId(tp, &PyId___get__);
if (get == NULL) {
if (tp->tp_descr_get == slot_tp_descr_get)
tp->tp_descr_get = NULL;
Py_INCREF(self);
return self;
}
if (obj == NULL)
obj = Py_None;
if (type == NULL)
type = Py_None;
return PyObject_CallFunctionObjArgs(get, self, obj, type, NULL);
}
CPython _PyType_LookupId __get__ type(mc) call_method mc.
call_method, _PyType_LookupId . Python , , , , self . self ( Descriptor) __get__ PyObject_CallFunctionObjArgs(get, self, obj, type, NULL).
__get__ Descriptor first, Python __get__, __set__ __delete__.