bpo-27794: Add `name` attribute to `property` class (GH-23967)
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index 172737a..7f3813f 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -204,6 +204,16 @@ def __doc__(cls):
return 'Second'
self.assertEqual(A.__doc__, 'Second')
+ def test_property_set_name_incorrect_args(self):
+ p = property()
+
+ for i in (0, 1, 3):
+ with self.assertRaisesRegex(
+ TypeError,
+ fr'^__set_name__\(\) takes 2 positional arguments but {i} were given$'
+ ):
+ p.__set_name__(*([0] * i))
+
# Issue 5890: subclasses of property do not preserve method __doc__ strings
class PropertySub(property):
@@ -299,6 +309,46 @@ def spam(self):
self.assertEqual(Foo.spam.__doc__, "a new docstring")
+class _PropertyUnreachableAttribute:
+ msg_format = None
+ obj = None
+ cls = None
+
+ def _format_exc_msg(self, msg):
+ return self.msg_format.format(msg)
+
+ @classmethod
+ def setUpClass(cls):
+ cls.obj = cls.cls()
+
+ def test_get_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("unreadable attribute")):
+ self.obj.foo
+
+ def test_set_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't set attribute")):
+ self.obj.foo = None
+
+ def test_del_property(self):
+ with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't delete attribute")):
+ del self.obj.foo
+
+
+class PropertyUnreachableAttributeWithName(_PropertyUnreachableAttribute, unittest.TestCase):
+ msg_format = "^{} 'foo'$"
+
+ class cls:
+ foo = property()
+
+
+class PropertyUnreachableAttributeNoName(_PropertyUnreachableAttribute, unittest.TestCase):
+ msg_format = "^{}$"
+
+ class cls:
+ pass
+
+ cls.foo = property()
+
if __name__ == '__main__':
unittest.main()