v
__get__
https://habr.com/ru/post/123216/
Через него какой-то долбаной магией создается bound метод
__get__
Size: a a a
v
__get__
__get__
fs
~ > python3
Python 3.8.6 (default, Nov 28 2020, 18:37:04)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def method(self):
... pass
...
>>> a, b = A(), A()
>>> id(a.method) == id(b.method)
True
>>> a.method == b.method
False
>>> a.method is b.method
False
>>> c, d = a.method, b.method
>>> id(c) == id(d)
False
>>> c, d = a.method, a.method
>>> id(c) == id(d)
False
R
~ > python3
Python 3.8.6 (default, Nov 28 2020, 18:37:04)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def method(self):
... pass
...
>>> a, b = A(), A()
>>> id(a.method) == id(b.method)
True
>>> a.method == b.method
False
>>> a.method is b.method
False
>>> c, d = a.method, b.method
>>> id(c) == id(d)
False
>>> c, d = a.method, a.method
>>> id(c) == id(d)
False
fs
fs
descr = _PyType_Lookup(tp, name);вот логика ответсвенная за это в
f = NULL;
if (descr != NULL) {
Py_INCREF(descr);
f = Py_TYPE(descr)->tp_descr_get;
if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, (PyObject *)Py_TYPE(obj));
if (res == NULL && suppress &&
PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
}
goto done;
}
}
_PyObject_GenericGetAttrWithDict
fs
fs
fs
R
fs
R
fs
>>> class A():зато можно так
... def m(self):
... print("1")
...
>>> a = A()
>>> a.m()
1
>>> A.m = lambda self : print("2")
>>> a.m()
2