Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1643,19 +1643,13 @@ 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
descriptor_types = (types.MemberDescriptorType, types.GetSetDescriptorType, types.WrapperDescriptorType)

result = getattr_static(some_object, 'foo')
if type(result) in descriptor_types:
if isinstance(result, descriptor_types):
try:
result = result.__get__()
result = result.__get__(some_object)
except AttributeError:
# descriptors can raise AttributeError to
# indicate there is no underlying value
Expand Down
Loading