diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_class.py | 18 | ||||
-rw-r--r-- | Lib/test/test_descrtut.py | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 894e0ca..bb35bae 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -641,6 +641,14 @@ class ClassTests(unittest.TestCase): class B: y = 0 __slots__ = ('z',) + class C: + __slots__ = ("y",) + + def __setattr__(self, name, value) -> None: + if name == "z": + super().__setattr__("y", 1) + else: + super().__setattr__(name, value) error_msg = "'A' object has no attribute 'x'" with self.assertRaisesRegex(AttributeError, error_msg): @@ -653,8 +661,16 @@ class ClassTests(unittest.TestCase): B().x with self.assertRaisesRegex(AttributeError, error_msg): del B().x - with self.assertRaisesRegex(AttributeError, error_msg): + with self.assertRaisesRegex( + AttributeError, + "'B' object has no attribute 'x' and no __dict__ for setting new attributes" + ): B().x = 0 + with self.assertRaisesRegex( + AttributeError, + "'C' object has no attribute 'x'" + ): + C().x = 0 error_msg = "'B' object attribute 'y' is read-only" with self.assertRaisesRegex(AttributeError, error_msg): diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index 7796031..13e3ea4 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -139,7 +139,7 @@ instance variables cannot be assigned to: >>> a.x1 = 1 Traceback (most recent call last): File "<stdin>", line 1, in ? - AttributeError: 'defaultdict2' object has no attribute 'x1' + AttributeError: 'defaultdict2' object has no attribute 'x1' and no __dict__ for setting new attributes >>> """ |