]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-103193: Improve `getattr_static` test coverage (GH-104286) (#104290)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 8 May 2023 14:44:10 +0000 (07:44 -0700)
committerGitHub <noreply@github.com>
Mon, 8 May 2023 14:44:10 +0000 (14:44 +0000)
gh-103193: Improve `getattr_static` test coverage (GH-104286)
(cherry picked from commit 921185ed050efbca2f0adeab79f676b7f8cc3660)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Lib/test/test_inspect.py

index efcbd63450b35d44a5198c5dde5bcbe309eca610..c44eed027e94039cb11b3f8af2a810a7d320808a 100644 (file)
@@ -2106,6 +2106,35 @@ class TestGetattrStatic(unittest.TestCase):
             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):