@@ -30,25 +30,25 @@ returns the unbound function (descriptor), not a bound method. The
3030caller is responsible for passing the object as the first argument when
3131calling it:
3232
33- class A:
34- def __enter__(self):
35- pass
36-
37- class B:
38- __slots__ = ("__enter__",)
39-
40- def __init__ (self):
41- def __enter__(self):
42- pass
43- self.__enter__ = __enter__
44-
45- a = A ()
46- b = B( )
47- enter_a = types.lookup_special_method(a , "__enter__")
48- enter_b = types.lookup_special_method(b, "__enter__" )
49-
50- result_a = enter_a(a )
51- result_b = enter_b(b)
33+ >>> class A:
34+ ... def __enter__(self):
35+ ... return "A.__enter__"
36+ ...
37+ >>> class B:
38+ ... __slots__ = ("__enter__",)
39+ ... def __init__(self):
40+ ... def __enter__ (self):
41+ ... return "B. __enter__"
42+ ... self.__enter__ = __enter__
43+ ...
44+ >>> a = A()
45+ >>> b = B ()
46+ >>> enter_a = types.lookup_special_method(a, "__enter__" )
47+ >>> enter_b = types.lookup_special_method(b , "__enter__")
48+ >>> enter_a(a )
49+ 'A.__enter__'
50+ >>> enter_b(b )
51+ 'B.__enter__'
5252
5353For other descriptors (property, etc.), it returns the result of the
5454descriptor's `__get__` method. Returns `None` if the method is not
5858static PyObject *
5959_types_lookup_special_method_impl (PyObject * module , PyObject * obj ,
6060 PyObject * attr )
61- /*[clinic end generated code: output=890e22cc0b8e0d34 input=fca9cb0e313a7848 ]*/
61+ /*[clinic end generated code: output=890e22cc0b8e0d34 input=e317288370125cd5 ]*/
6262{
6363 if (!PyUnicode_Check (attr )) {
6464 PyErr_Format (PyExc_TypeError ,
0 commit comments