Skip to content

Commit 5e9f471

Browse files
furkanondercarljm
andauthored
gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)
Co-authored-by: Carl Meyer <[email protected]>
1 parent a454a66 commit 5e9f471

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Lib/inspect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,10 @@ def getattr_static(obj, attr, default=_sentinel):
18351835
klass_result = _check_class(klass, attr)
18361836

18371837
if instance_result is not _sentinel and klass_result is not _sentinel:
1838-
if (_check_class(type(klass_result), '__get__') is not _sentinel and
1839-
_check_class(type(klass_result), '__set__') is not _sentinel):
1838+
if _check_class(type(klass_result), "__get__") is not _sentinel and (
1839+
_check_class(type(klass_result), "__set__") is not _sentinel
1840+
or _check_class(type(klass_result), "__delete__") is not _sentinel
1841+
):
18401842
return klass_result
18411843

18421844
if instance_result is not _sentinel:

Lib/test/test_inspect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,9 @@ class Foo(object):
20522052
descriptor.__set__ = lambda s, i, v: None
20532053
self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
20542054

2055+
del descriptor.__set__
2056+
descriptor.__delete__ = lambda s, i, o: None
2057+
self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])
20552058

20562059
def test_metaclass_with_descriptor(self):
20572060
class descriptor(object):
Lines changed: 1 addition & 0 deletions
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)