File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1192,6 +1192,10 @@ roughly equivalent to:
1192
1192
"Emulate method_getattro() in Objects/classobject.c"
1193
1193
return getattr(self.__func__, name)
1194
1194
1195
+ def __get__(self, obj, objtype=None):
1196
+ "Emulate method_descr_get() in Objects/classobject.c"
1197
+ return self
1198
+
1195
1199
To support automatic creation of methods, functions include the
1196
1200
:meth: `__get__ ` method for binding methods during attribute access. This
1197
1201
means that functions are non-data descriptors that return bound methods
@@ -1214,8 +1218,20 @@ descriptor works in practice:
1214
1218
.. testcode ::
1215
1219
1216
1220
class D:
1217
- def f(self, x):
1218
- return x
1221
+ def f(self):
1222
+ return self
1223
+
1224
+ class D2:
1225
+ pass
1226
+
1227
+ .. doctest ::
1228
+ :hide:
1229
+
1230
+ >>> d = D()
1231
+ >>> d2 = D2()
1232
+ >>> d2.f = d.f.__get__ (d2, D2)
1233
+ >>> d2.f() is d
1234
+ True
1219
1235
1220
1236
The function has a :term: `qualified name ` attribute to support introspection:
1221
1237
You can’t perform that action at this time.
0 commit comments