Skip to content

Commit

Permalink
Check for __delete__ to detect data descriptors, as in https://github…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki committed Nov 24, 2023
1 parent aac6c49 commit 3d1564d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pure_eval/my_getattr_static.py
Expand Up @@ -79,8 +79,10 @@ def getattr_static(obj, attr):
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 _resolve_descriptor(klass_result, obj, klass)

if instance_result is not _sentinel:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_getattr_static.py
Expand Up @@ -187,6 +187,10 @@ class Foo(object):
descriptor.__set__ = lambda s, i, v: None
self.assert_cannot_getattr(foo, 'd')

del descriptor.__set__
descriptor.__delete__ = lambda s, i, o: None
self.assert_cannot_getattr(foo, 'd')

def test_metaclass_with_descriptor(self):
class descriptor(object):
def __get__(self, instance, owner):
Expand Down

0 comments on commit 3d1564d

Please sign in to comment.