[pypy-commit] pypy py3k: allow setting class docstrings
pjenvey
pypy.commits at gmail.com
Sat May 7 14:53:24 EDT 2016
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r84279:605722e607a3
Date: 2016-05-07 11:49 -0700
http://bitbucket.org/pypy/pypy/changeset/605722e607a3/
Log: allow setting class docstrings
diff --git a/lib-python/3/test/test_descr.py b/lib-python/3/test/test_descr.py
--- a/lib-python/3/test/test_descr.py
+++ b/lib-python/3/test/test_descr.py
@@ -4515,9 +4515,9 @@
with self.assertRaises(TypeError) as cm:
type(list).__dict__["__doc__"].__set__(list, "blah")
self.assertIn("can't set list.__doc__", str(cm.exception))
- with self.assertRaises(TypeError) as cm:
+ with self.assertRaises((AttributeError, TypeError)) as cm:
type(X).__dict__["__doc__"].__delete__(X)
- self.assertIn("can't delete X.__doc__", str(cm.exception))
+ self.assertIn("delete", str(cm.exception))
self.assertEqual(X.__doc__, "banana")
def test_qualname(self):
diff --git a/pypy/interpreter/test/test_class.py b/pypy/interpreter/test/test_class.py
--- a/pypy/interpreter/test/test_class.py
+++ b/pypy/interpreter/test/test_class.py
@@ -123,3 +123,14 @@
assert C.__qualname__ == 'test_qualname.<locals>.C'
assert C.D.__qualname__ == 'test_qualname.<locals>.C.D'
assert not hasattr(C(), '__qualname__')
+
+ def test_set_doc(self):
+ class X:
+ "elephant"
+ X.__doc__ = "banana"
+ assert X.__doc__ == "banana"
+ raises(TypeError, lambda:
+ type(list).__dict__["__doc__"].__set__(list, "blah"))
+ raises((AttributeError, TypeError), lambda:
+ type(X).__dict__["__doc__"].__delete__(X))
+ assert X.__doc__ == "banana"
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -853,6 +853,12 @@
else:
return space.get(w_result, space.w_None, w_type)
+def descr_set__doc(space, w_type, w_value):
+ w_type = _check(space, w_type)
+ if not w_type.is_heaptype():
+ raise oefmt(space.w_TypeError, "can't set %N.__doc__", w_type)
+ w_type.setdictvalue(space, '__doc__', w_value)
+
def descr__dir(space, w_type):
from pypy.objspace.std.util import _classdir
return space.call_function(space.w_list, _classdir(space, w_type))
@@ -928,7 +934,7 @@
__base__ = GetSetProperty(descr__base),
__mro__ = GetSetProperty(descr_get__mro__),
__dict__ = GetSetProperty(descr_get_dict),
- __doc__ = GetSetProperty(descr__doc),
+ __doc__ = GetSetProperty(descr__doc, descr_set__doc),
__dir__ = gateway.interp2app(descr__dir),
mro = gateway.interp2app(descr_mro),
__flags__ = GetSetProperty(descr__flags),
More information about the pypy-commit
mailing list