From 3b92a4656d987e6def05995681c2c9b44b31a527 Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Wed, 27 May 2026 17:52:02 +0800 Subject: [PATCH 1/2] 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 3b34445f019c36..61ec3509296b3b 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1667,19 +1667,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 From dceb244bcf57c12ae3e862454e1f525e6c456bdb Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Sun, 5 Jul 2026 17:11:38 +0800 Subject: [PATCH 2/2] fix --- Doc/library/inspect.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 61ec3509296b3b..695008b58c10f7 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1668,10 +1668,9 @@ for arbitrary getset descriptors invoking these may trigger code execution:: import types - descriptor_types = (types.MemberDescriptorType, types.GetSetDescriptorType, types.WrapperDescriptorType) result = getattr_static(some_object, 'foo') - if isinstance(result, descriptor_types): + if isinstance(result, (types.MemberDescriptorType, types.GetSetDescriptorType, types.WrapperDescriptorType)): try: result = result.__get__(some_object) except AttributeError: