@@ -8,7 +8,6 @@ static PyMemberDef type_members[] = {
88 {"__basicsize__" , T_INT , offsetof(PyTypeObject ,tp_basicsize ),READONLY },
99 {"__itemsize__" , T_INT , offsetof(PyTypeObject , tp_itemsize ), READONLY },
1010 {"__flags__" , T_LONG , offsetof(PyTypeObject , tp_flags ), READONLY },
11- {"__doc__" , T_STRING , offsetof(PyTypeObject , tp_doc ), READONLY },
1211 {"__weakrefoffset__" , T_LONG ,
1312 offsetof(PyTypeObject , tp_weaklistoffset ), READONLY },
1413 {"__base__" , T_OBJECT , offsetof(PyTypeObject , tp_base ), READONLY },
@@ -1044,9 +1043,9 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
10441043 }
10451044
10461045 /* Set tp_doc to a copy of dict['__doc__'], if the latter is there
1047- and is a string (tp_doc is a char* -- can't copy a general object
1048- into it).
1049- XXX What if it's a Unicode string? Don't know -- this ignores it .
1046+ and is a string. Note that the tp_doc slot will only be used
1047+ by C code -- python code will use the version in tp_dict, so
1048+ it isn't that important that non string __doc__'s are ignored .
10501049 */
10511050 {
10521051 PyObject * doc = PyDict_GetItemString (dict , "__doc__" );
@@ -2024,6 +2023,19 @@ PyType_Ready(PyTypeObject *type)
20242023 inherit_slots (type , (PyTypeObject * )b );
20252024 }
20262025
2026+ /* if the type dictionary doesn't contain a __doc__, set it from
2027+ the tp_doc slot.
2028+ */
2029+ if (PyDict_GetItemString (type -> tp_dict , "__doc__" ) == NULL ) {
2030+ if (type -> tp_doc != NULL ) {
2031+ PyObject * doc = PyString_FromString (type -> tp_doc );
2032+ PyDict_SetItemString (type -> tp_dict , "__doc__" , doc );
2033+ Py_DECREF (doc );
2034+ } else {
2035+ PyDict_SetItemString (type -> tp_dict , "__doc__" , Py_None );
2036+ }
2037+ }
2038+
20272039 /* Some more special stuff */
20282040 base = type -> tp_base ;
20292041 if (base != NULL ) {
0 commit comments