From 49d3e6a08ecf2498281204c47d150610cfd1fe26 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 10 May 2024 16:35:42 +0300 Subject: [PATCH 1/3] gh-118899: Add tests for `NotImplemented` attribute access --- Lib/test/test_builtin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index a7631f92e7ea81..a7b35be936f8d9 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -2138,6 +2138,22 @@ def test_bool_notimplemented(self): with self.assertRaisesRegex(TypeError, msg): not NotImplemented + def test_not_implemented(self): + self.assertIs(type(NotImplemented), NotImplemented.__class__) + self.assertIs(type(NotImplemented).__class__, type) + + # Missing instance attributes: + with self.assertRaises(AttributeError): + NotImplemented.prop + with self.assertRaises(AttributeError): + NotImplemented.prop = 1 + + # Missing class attributes: + with self.assertRaises(AttributeError): + type(NotImplemented).prop + with self.assertRaises(TypeError): + type(NotImplemented).prop = 1 + class TestBreakpoint(unittest.TestCase): def setUp(self): From abaff2ff266a320821cb35ab3a177cab6670b46a Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 12 May 2024 13:57:25 +0300 Subject: [PATCH 2/3] Also test `...` --- Lib/test/test_builtin.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index a7b35be936f8d9..1114f77870b518 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -2138,21 +2138,23 @@ def test_bool_notimplemented(self): with self.assertRaisesRegex(TypeError, msg): not NotImplemented - def test_not_implemented(self): - self.assertIs(type(NotImplemented), NotImplemented.__class__) - self.assertIs(type(NotImplemented).__class__, type) - - # Missing instance attributes: - with self.assertRaises(AttributeError): - NotImplemented.prop - with self.assertRaises(AttributeError): - NotImplemented.prop = 1 - - # Missing class attributes: - with self.assertRaises(AttributeError): - type(NotImplemented).prop - with self.assertRaises(TypeError): - type(NotImplemented).prop = 1 + 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 + with self.assertRaises(AttributeError): + singleton.prop = 1 + + # Missing class attributes: + with self.assertRaises(AttributeError): + type(singleton).prop + with self.assertRaises(TypeError): + type(singleton).prop = 1 class TestBreakpoint(unittest.TestCase): From 8550f842e64a9956dd3af8934fa20cd2c14149fe Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 12 May 2024 16:39:49 +0300 Subject: [PATCH 3/3] Address review --- Lib/test/test_builtin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 1114f77870b518..d7ba58847a2992 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -2145,16 +2145,16 @@ def test_singleton_attribute_access(self): self.assertIs(type(singleton).__class__, type) # Missing instance attributes: - with self.assertRaises(AttributeError): - singleton.prop with self.assertRaises(AttributeError): singleton.prop = 1 + with self.assertRaises(AttributeError): + singleton.prop # Missing class attributes: - with self.assertRaises(AttributeError): - type(singleton).prop with self.assertRaises(TypeError): type(singleton).prop = 1 + with self.assertRaises(AttributeError): + type(singleton).prop class TestBreakpoint(unittest.TestCase): 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