]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-75367: Fix data descriptor detection in inspect.getattr_static (GH-104517...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 16 May 2023 17:57:34 +0000 (10:57 -0700)
committerGitHub <noreply@github.com>
Tue, 16 May 2023 17:57:34 +0000 (17:57 +0000)
gh-75367: Fix data descriptor detection in inspect.getattr_static (GH-104517)
(cherry picked from commit 5e9f471e7db30893fb3f42681f17fdcdb70069ee)

Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
Co-authored-by: Carl Meyer <carl@oddbird.net>
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst [new file with mode: 0644]

index 75d33f2ce7e73e77a07dc56fa2c7b098115855d6..14569a510a0501ad3b13ab9fcf01dfb551247db8 100644 (file)
@@ -1829,8 +1829,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:
index c44eed027e94039cb11b3f8af2a810a7d320808a..2783f7f8a08e88ecd3a3b11539b95bc6d67ec101 100644 (file)
@@ -1993,6 +1993,9 @@ class TestGetattrStatic(unittest.TestCase):
         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 (file)
index 0000000..554c425
--- /dev/null
@@ -0,0 +1 @@
+Fix data descriptor detection in  :func:`inspect.getattr_static`.