[3.11] gh-75367: Fix data descriptor detection in inspect.getattr_sta… · python/cpython@f748fc9

GitHub

Original file line numberDiff line numberDiff line change@@ -1829,8 +1829,10 @@ def getattr_static(obj, attr, default=_sentinel):

18291829klass_result=_check_class(klass, attr)

1830183018311831ifinstance_resultisnot_sentinelandklass_resultisnot_sentinel:

1832-if (_check_class(type(klass_result), '__get__') isnot_sentineland

1833-_check_class(type(klass_result), '__set__') isnot_sentinel):

1832+if_check_class(type(klass_result), "__get__") isnot_sentineland (

1833+_check_class(type(klass_result), "__set__") isnot_sentinel

1834+or_check_class(type(klass_result), "__delete__") isnot_sentinel

1835+ ):

18341836returnklass_result

1835183718361838ifinstance_resultisnot_sentinel:

Original file line numberDiff line numberDiff line change@@ -1993,6 +1993,9 @@ class Foo(object):

19931993descriptor.__set__=lambdas, i, v: None

19941994self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])

199519951996+deldescriptor.__set__

1997+descriptor.__delete__=lambdas, i, o: None

1998+self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])

1996199919972000deftest_metaclass_with_descriptor(self):

19982001classdescriptor(object):

Original file line numberDiff line numberDiff line change@@ -0,0 +1 @@

1+Fix data descriptor detection in :func:`inspect.getattr_static`.