]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118899: Add tests for `NotImplemented` attribute access (#118902)
authorNikita Sobolev <mail@sobolevn.me>
Sun, 12 May 2024 14:00:49 +0000 (17:00 +0300)
committerGitHub <noreply@github.com>
Sun, 12 May 2024 14:00:49 +0000 (14:00 +0000)
Lib/test/test_builtin.py

index a7631f92e7ea81d87620d3f878168d23fee6a51c..d7ba58847a2992e8e8f9fa04f99fa05317973cd8 100644 (file)
@@ -2138,6 +2138,24 @@ class BuiltinTest(unittest.TestCase):
         with self.assertRaisesRegex(TypeError, msg):
             not NotImplemented
 
+    def test_singleton_attribute_access(self):
+        for singleton in (NotImplemented, Ellipsis):
+            with self.subTest(singleton):
+                self.assertIs(type(singleton), singleton.__class__)
+                self.assertIs(type(singleton).__class__, type)
+
+                # Missing instance attributes:
+                with self.assertRaises(AttributeError):
+                    singleton.prop = 1
+                with self.assertRaises(AttributeError):
+                    singleton.prop
+
+                # Missing class attributes:
+                with self.assertRaises(TypeError):
+                    type(singleton).prop = 1
+                with self.assertRaises(AttributeError):
+                    type(singleton).prop
+
 
 class TestBreakpoint(unittest.TestCase):
     def setUp(self):