data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 418337b..36af26c 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4496,6 +4496,26 @@
c[1:2] = 3
self.assertEqual(c.value, 3)
+ def test_set_and_no_get(self):
+ # See
+ # http://mail.python.org/pipermail/python-dev/2010-January/095637.html
+ class Descr(object):
+
+ def __init__(self, name):
+ self.name = name
+
+ def __set__(self, obj, value):
+ obj.__dict__[self.name] = value
+ descr = Descr("a")
+
+ class X(object):
+ a = descr
+
+ x = X()
+ self.assertIs(x.a, descr)
+ x.a = 42
+ self.assertEqual(x.a, 42)
+
def test_getattr_hooks(self):
# issue 4230