From 67912be4f611e8c4ec11c5ea4c050594f1f68072 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Tue, 16 May 2023 02:48:46 +0300 Subject: [PATCH 1/4] fix data descriptor detection in inspect.getattr_static --- Lib/inspect.py | 6 ++++-- Lib/test/test_inspect.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index a64e85e4fd67a4..63f5aa91d270b7 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 364f75db908b05..1b282f7528bf47 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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): From de2a892558d1f352828aea39f7e5059449384edf Mon Sep 17 00:00:00 2001 From: Furkan Onder Date: Tue, 16 May 2023 13:41:53 +0300 Subject: [PATCH 2/4] Update Lib/test/test_inspect.py Co-authored-by: Carl Meyer --- Lib/test/test_inspect.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 1b282f7528bf47..0590e49d0e1a43 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -2052,20 +2052,9 @@ 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) - + 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): From ccb7fe789d275a82aead88515171803142d7e117 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 11:02:47 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst diff --git a/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst new file mode 100644 index 00000000000000..5704385e73a8dc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst @@ -0,0 +1 @@ +Fix data descriptor detection in :meth:`inspect.getattr_static`. From 4df0469d98b3f4ae625057053c05c738b3fa1723 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 16 May 2023 18:02:39 +0100 Subject: [PATCH 4/4] Fix sphinx role --- .../next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst index 5704385e73a8dc..554c425e6a7864 100644 --- a/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst +++ b/Misc/NEWS.d/next/Library/2023-05-16-11-02-44.gh-issue-75367.qLWR35.rst @@ -1 +1 @@ -Fix data descriptor detection in :meth:`inspect.getattr_static`. +Fix data descriptor detection in :func:`inspect.getattr_static`. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy