changeset: 104356:0b726193ec3c branch: 3.6 parent: 104351:b06e75ae1981 parent: 104354:5c459b0f2b75 user: Serhiy Storchaka date: Fri Oct 07 23:25:46 2016 +0300 files: Misc/ACKS Misc/NEWS Objects/typeobject.c description: Issue #18287: PyType_Ready() now checks that tp_name is not NULL. Original patch by Niklas Koep. diff -r b06e75ae1981 -r 0b726193ec3c Doc/c-api/typeobj.rst --- a/Doc/c-api/typeobj.rst Fri Oct 07 22:24:20 2016 +0300 +++ b/Doc/c-api/typeobj.rst Fri Oct 07 23:25:46 2016 +0300 @@ -116,7 +116,8 @@ If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the :attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined (unless explicitly set in the dictionary, as explained above). This means your - type will be impossible to pickle. + type will be impossible to pickle. Additionally, it will not be listed in + module documentations created with pydoc. This field is not inherited by subtypes. diff -r b06e75ae1981 -r 0b726193ec3c Doc/extending/newtypes.rst --- a/Doc/extending/newtypes.rst Fri Oct 07 22:24:20 2016 +0300 +++ b/Doc/extending/newtypes.rst Fri Oct 07 23:25:46 2016 +0300 @@ -129,7 +129,9 @@ Note that the name is a dotted name that includes both the module name and the name of the type within the module. The module in this case is :mod:`noddy` and -the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`. :: +the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`. +One side effect of using an undotted name is that the pydoc documentation tool +will not list the new type in the module documentation. :: sizeof(noddy_NoddyObject), /* tp_basicsize */ diff -r b06e75ae1981 -r 0b726193ec3c Misc/ACKS --- a/Misc/ACKS Fri Oct 07 22:24:20 2016 +0300 +++ b/Misc/ACKS Fri Oct 07 23:25:46 2016 +0300 @@ -783,6 +783,7 @@ Kubilay Kocak Greg Kochanski Manvisha Kodali +Niklas Koep Damon Kohler Marko Kohtala Vajrasky Kok diff -r b06e75ae1981 -r 0b726193ec3c Misc/NEWS --- a/Misc/NEWS Fri Oct 07 22:24:20 2016 +0300 +++ b/Misc/NEWS Fri Oct 07 23:25:46 2016 +0300 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #18287: PyType_Ready() now checks that tp_name is not NULL. + Original patch by Niklas Koep. + - Issue #24098: Fixed possible crash when AST is changed in process of compiling it. diff -r b06e75ae1981 -r 0b726193ec3c Objects/typeobject.c --- a/Objects/typeobject.c Fri Oct 07 22:24:20 2016 +0300 +++ b/Objects/typeobject.c Fri Oct 07 23:25:46 2016 +0300 @@ -4893,6 +4893,12 @@ _Py_AddToAllObjects((PyObject *)type, 0); #endif + if (type->tp_name == NULL) { + PyErr_Format(PyExc_SystemError, + "Type does not define the tp_name field."); + goto error; + } + /* Initialize tp_base (defaults to BaseObject unless that's us) */ base = type->tp_base; if (base == NULL && type != &PyBaseObject_Type) {