Skip to content

Commit

Permalink
gh-75367: Fix data descriptor detection in inspect.getattr_static (#1…
Browse files Browse the repository at this point in the history
…04517)

Co-authored-by: Carl Meyer <carl@oddbird.net>
  • Loading branch information
furkanonder and carljm committed May 16, 2023
1 parent a454a66 commit 5e9f471
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix data descriptor detection in :func:`inspect.getattr_static`.

0 comments on commit 5e9f471

Please sign in to comment.