[pypy-issue] Issue #2446: cpyext: tp_doc field not reflected on Python side (pypy/pypy)
Wenzel Jakob
issues-reply at bitbucket.org
Mon Dec 5 17:04:12 EST 2016
New issue 2446: cpyext: tp_doc field not reflected on Python side
https://bitbucket.org/pypy/pypy/issues/2446/cpyext-tp_doc-field-not-reflected-on
Wenzel Jakob:
Hi,
while porting pybind11 to PyPy, I've noticed that cpyext does not seem to propagate the ``tp_doc`` field to the ``__doc__`` field of a newly created type. This happens even in the case where ``tp_doc`` is properly set before the ``PyType_Ready`` call and never touched afterwards.
My diagnostics for an example type print the following info about the fields just before ``PyType_Ready``:
```
==================================
** Before call to PyType_Ready **
tp_name = ExamplePythonTypes
tp_base = NULL
tp_bases = NULL
ob_type = <class '__main__.ExamplePythonTypes__Meta'>
tp_flags = 133115
tp_basicsize = 56
tp_weaklistoffset = 32
tp_dictoffset = 0
tp_doc = Example 2 documentation
==================================
==================================
** After call to PyType_Ready **
tp_name = ExamplePythonTypes
tp_base = <type 'object'>
tp_bases = (<type 'object'>,)
ob_type = <class '__main__.ExamplePythonTypes__Meta'>
tp_flags = 137211
tp_basicsize = 56
tp_weaklistoffset = 32
tp_dictoffset = 0
tp_doc = Example 2 documentation
==================================
```
If I later inspect the docstring on the Python side, I just get an empty string:
```
>>>> pybind11_tests.ExamplePythonTypes.__doc__
>>>>
```
(however, I would have expected to get ``Example 2 documentation``)
I assume that PyPy was supposed to make a copy of that string when ``PyType_Ready`` is called -- but just in case, the C char array also still exists (i.e. pybind11 doesn't delete it).
So I assume this is some kind of a bug.
More information about the pypy-issue
mailing list