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:
11921192            "Emulate method_getattro() in Objects/classobject.c"
11931193            return getattr(self.__func__, name)
11941194
1195+         def __get__(self, obj, objtype=None):
1196+             "Emulate method_descr_get() in Objects/classobject.c"
1197+             return self
1198+ 
11951199To support automatic creation of methods, functions include the
11961200:meth: `__get__ ` method for binding methods during attribute access.  This
11971201means that functions are non-data descriptors that return bound methods
@@ -1214,8 +1218,20 @@ descriptor works in practice:
12141218.. testcode ::
12151219
12161220    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 
12191235
12201236The function has a :term: `qualified name ` attribute to support introspection:
12211237
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments