[Python-checkins] gh-103193: Improve `getattr_static` test coverage (#104286)

AlexWaygood webhook-mailer at python.org
Mon May 8 10:19:31 EDT 2023


https://github.com/python/cpython/commit/921185ed050efbca2f0adeab79f676b7f8cc3660
commit: 921185ed050efbca2f0adeab79f676b7f8cc3660
branch: main
author: Alex Waygood <Alex.Waygood at Gmail.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-05-08T15:18:36+01:00
summary:

gh-103193: Improve `getattr_static` test coverage (#104286)

files:
M Lib/test/test_inspect.py

diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index dd0325a43e0f..d2b2f3171e78 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2187,6 +2187,35 @@ class Thing(metaclass=Meta):
             inspect.getattr_static(Thing, "spam")
         self.assertFalse(Thing.executed)
 
+    def test_custom___getattr__(self):
+        test = self
+        test.called = False
+
+        class Foo:
+            def __getattr__(self, attr):
+                test.called = True
+                return {}
+
+        with self.assertRaises(AttributeError):
+            inspect.getattr_static(Foo(), 'whatever')
+
+        self.assertFalse(test.called)
+
+    def test_custom___getattribute__(self):
+        test = self
+        test.called = False
+
+        class Foo:
+            def __getattribute__(self, attr):
+                test.called = True
+                return {}
+
+        with self.assertRaises(AttributeError):
+            inspect.getattr_static(Foo(), 'really_could_be_anything')
+
+        self.assertFalse(test.called)
+
+
 class TestGetGeneratorState(unittest.TestCase):
 
     def setUp(self):



More information about the Python-checkins mailing list