Skip to content

Commit 1de0a15

Browse files
furkanondercarljm
authored andcommitted
pythongh-75367: Fix data descriptor detection in inspect.getattr_static (pythonGH-104517)
(cherry picked from commit 5e9f471) Co-authored-by: Furkan Onder <[email protected]> Co-authored-by: Carl Meyer <[email protected]>
1 parent 9cac6c4 commit 1de0a15

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Lib/inspect.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,10 @@ def getattr_static(obj, attr, default=_sentinel):
18291829
klass_result = _check_class(klass, attr)
18301830

18311831
if instance_result is not _sentinel and klass_result is not _sentinel:
1832-
if (_check_class(type(klass_result), '__get__') is not _sentinel and
1833-
_check_class(type(klass_result), '__set__') is not _sentinel):
1832+
if _check_class(type(klass_result), "__get__") is not _sentinel and (
1833+
_check_class(type(klass_result), "__set__") is not _sentinel
1834+
or _check_class(type(klass_result), "__delete__") is not _sentinel
1835+
):
18341836
return klass_result
18351837

18361838
if instance_result is not _sentinel:

Lib/test/test_inspect.py

+3
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,9 @@ class Foo(object):
19931993
descriptor.__set__ = lambda s, i, v: None
19941994
self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
19951995

1996+
del descriptor.__set__
1997+
descriptor.__delete__ = lambda s, i, o: None
1998+
self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
19961999

19972000
def test_metaclass_with_descriptor(self):
19982001
class descriptor(object):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix data descriptor detection in :func:`inspect.getattr_static`.

0 commit comments

Comments
 (0)