[Python-checkins] gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)

AlexWaygood webhook-mailer at python.org
Tue May 16 13:34:51 EDT 2023


https://github.com/python/cpython/commit/5e9f471e7db30893fb3f42681f17fdcdb70069ee
commit: 5e9f471e7db30893fb3f42681f17fdcdb70069ee
branch: main
author: Furkan Onder <furkanonder at protonmail.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-05-16T17:34:44Z
summary:

gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)

Co-authored-by: Carl Meyer <carl at oddbird.net>

files:
A Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst
M Lib/inspect.py
M Lib/test/test_inspect.py

diff --git a/Lib/inspect.py b/Lib/inspect.py
index a64e85e4fd67..63f5aa91d270 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1835,8 +1835,10 @@ def getattr_static(obj, attr, default=_sentinel):
     klass_result = _check_class(klass, attr)
 
     if instance_result is not _sentinel and klass_result is not _sentinel:
-        if (_check_class(type(klass_result), '__get__') is not _sentinel and
-            _check_class(type(klass_result), '__set__') is not _sentinel):
+        if _check_class(type(klass_result), "__get__") is not _sentinel and (
+            _check_class(type(klass_result), "__set__") is not _sentinel
+            or _check_class(type(klass_result), "__delete__") is not _sentinel
+        ):
             return klass_result
 
     if instance_result is not _sentinel:
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 364f75db908b..0590e49d0e1a 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2052,6 +2052,9 @@ class Foo(object):
         descriptor.__set__ = lambda s, i, v: None
         self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
 
+        del descriptor.__set__
+        descriptor.__delete__ = lambda s, i, o: None
+        self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
 
     def test_metaclass_with_descriptor(self):
         class descriptor(object):
diff --git a/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst
new file mode 100644
index 000000000000..554c425e6a78
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst
@@ -0,0 +1 @@
+Fix data descriptor detection in  :func:`inspect.getattr_static`.



More information about the Python-checkins mailing list