Author: Matti Picus <matti.pi...@gmail.com> Branch: cpyext-add_newdoc Changeset: r91680:895424ab836c Date: 2017-07-03 07:56 -0400 http://bitbucket.org/pypy/pypy/changeset/895424ab836c/
Log: allow assignment to NULL tp_doc even after PyType_Ready diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -366,6 +366,15 @@ if pto.c_tp_new: add_tp_new_wrapper(space, dict_w, pto) +def maybe_set_doc(space, w_type): + pto = rffi.cast(PyTypeObjectPtr, make_ref(space, w_type)) + if pto and pto.c_tp_doc and space.is_none(w_type.w_doc): + w_type.w_doc = space.newtext( + rffi.charp2str(cts.cast('char*', pto.c_tp_doc))) + # compatibility with CPython - assignment to tp_doc + # does not automatically assign to __dic__['__doc__'] + # w_type.dict_w.setdefault('__doc__', w_type.w_doc) + @slot_function([PyObject, PyObject, PyObject], PyObject) def tp_new_wrapper(space, self, w_args, w_kwds): self_pytype = rffi.cast(PyTypeObjectPtr, self) 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 @@ -882,6 +882,9 @@ type(name, bases, dict) -> a new type""") w_type = _check(space, w_type) if not w_type.is_heaptype(): + if space.is_none(w_type.w_doc) and w_type.is_cpytype(): + from pypy.module.cpyext.typeobject import maybe_set_doc + maybe_set_doc(space, w_type) return w_type.w_doc w_result = w_type.getdictvalue(space, '__doc__') if w_result is None: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit