[pypy-commit] pypy py3.5: Make <property>.__doc__ writable

rlamy pypy.commits at gmail.com
Mon Oct 10 12:53:53 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r87697:a2af1f696a0e
Date: 2016-10-10 17:53 +0100
http://bitbucket.org/pypy/pypy/changeset/a2af1f696a0e/

Log:	Make <property>.__doc__ writable

diff --git a/pypy/module/__builtin__/descriptor.py b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -196,6 +196,13 @@
     def deleter(self, space, w_deleter):
         return self._copy(space, w_deleter=w_deleter)
 
+    def get_doc(self, space):
+        return self.w_doc
+
+    def set_doc(self, space, w_doc):
+        self.w_doc = w_doc
+        self.getter_doc = False
+
     def _copy(self, space, w_getter=None, w_setter=None, w_deleter=None):
         if w_getter is None:
             w_getter = self.w_fget
@@ -244,5 +251,5 @@
 )
 # This allows there to be a __doc__ of the property type and a __doc__
 # descriptor for the instances.
-W_Property.typedef.rawdict['__doc__'] = interp_attrproperty_w('w_doc',
-                                                              W_Property)
+W_Property.typedef.rawdict['__doc__'] = GetSetProperty(
+    W_Property.get_doc, W_Property.set_doc)
diff --git a/pypy/module/__builtin__/test/test_descriptor.py b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -53,7 +53,7 @@
         assert isinstance(x, Classm)
 
     def test_property_simple(self):
-        
+
         class a(object):
             def _get(self): return 42
             def _set(self, value): raise AttributeError
@@ -137,7 +137,7 @@
             assert message.startswith('super(type, obj): obj must be an instance or subtype of type')
 
     def test_super_various(self):
-        
+
         class A(object):
             def meth(self, a):
                 return "A(%r)" % a
@@ -367,11 +367,13 @@
         assert "fdel" in attrs
 
         assert raw.__doc__ == "I'm the x property."
+        raw.__doc__ = "modified"
+        assert raw.__doc__ == "modified"
         assert raw.fget is C.__dict__['getx']
         assert raw.fset is C.__dict__['setx']
         assert raw.fdel is C.__dict__['delx']
 
-        for attr in "__doc__", "fget", "fset", "fdel":
+        for attr in "fget", "fset", "fdel":
             try:
                 setattr(raw, attr, 42)
             # it raises TypeError on pypy, AttributeError on CPython: we catch
@@ -407,10 +409,10 @@
 
     def test_property_subclass_with_init(self):
         l = []
-        
+
         def x(self):
             l.append('x')
-        
+
         class P(property):
             def __init__(self):
                 property.__init__(self, x)


More information about the pypy-commit mailing list