diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 3b34445f019c36c..695008b58c10f79 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1667,19 +1667,12 @@ You can handle these with code like the following. Note that for arbitrary getset descriptors invoking these may trigger code execution:: - # example code for resolving the builtin descriptor types - class _foo: - __slots__ = ['foo'] - - slot_descriptor = type(_foo.foo) - getset_descriptor = type(type(open(__file__)).name) - wrapper_descriptor = type(str.__dict__['__add__']) - descriptor_types = (slot_descriptor, getset_descriptor, wrapper_descriptor) + import types result = getattr_static(some_object, 'foo') - if type(result) in descriptor_types: + if isinstance(result, (types.MemberDescriptorType, types.GetSetDescriptorType, types.WrapperDescriptorType)): try: - result = result.__get__() + result = result.__get__(some_object) except AttributeError: # descriptors can raise AttributeError to # indicate there is no underlying value