8000 gh-75367: fix data descriptor detection in inspect.getattr_static by furkanonder · Pull Request #104517 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-75367: fix data descriptor detection in inspect.getattr_static #104517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations 8000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix data descriptor detection in inspect.getattr_static
  • Loading branch information
furkanonder committed May 15, 2023
commit 67912be4f611e8c4ec11c5ea4c050594f1f68072
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
14 changes: 14 additions & 0 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,20 @@ class Foo(object):
descriptor.__set__ = lambda s, i, v: None
self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d'])

class DescriptorGetDelete:
def __get__(self, instance, klass):
return 'bar'
def __delete__(self, instance, klass):
pass
class Bar:
get_delete = DescriptorGetDelete()
def __init__(self):
self.__dict__['get_delete'] = 42

bar = Bar()
self.assertNotEqual(inspect.getattr_static(bar, 'get_delete'), 42)
self.assertIsInstance(inspect.getattr_static(bar, 'get_delete'), DescriptorGetDelete)


def test_metaclass_with_descriptor(self):
class descriptor(object):
Expand Down
0