From 8b5b1fe5f7acd5b2aa3b0e9bb7cbe6959175f59c Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Wed, 27 May 2026 17:52:02 +0800 Subject: [PATCH] commit --- Doc/library/inspect.rst | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 92840e702fbbfe6..6f44fdfbd3b4ab0 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -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