mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-75367: Fix data descriptor detection in inspect.getattr_static (#104517)
Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
parent
a454a6651b
commit
5e9f471e7d
3 changed files with 8 additions and 2 deletions
|
@ -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:
|
||||
|
|
|
@ -2052,6 +2052,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):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix data descriptor detection in :func:`inspect.getattr_static`.
|
Loading…
Add table
Add a link
Reference in a new issue