]> granicus.if.org Git - python/commitdiff
Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 7 Oct 2016 20:24:35 +0000 (23:24 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 7 Oct 2016 20:24:35 +0000 (23:24 +0300)
Original patch by Niklas Koep.

Doc/c-api/typeobj.rst
Doc/extending/newtypes.rst
Misc/ACKS
Misc/NEWS
Objects/typeobject.c

index a9981fe441b0e50518d06f918710e393b696b7b9..83dd0a392f163b7b513cd9663f2b41d9d0ddeede 100644 (file)
@@ -122,7 +122,8 @@ type objects) *must* have the :attr:`ob_size` field.
    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.
 
index a642912b19f91439610ba2f45d5f77f247499db9..ee173b7e23212748136c0cf129ce01af1851bce2 100644 (file)
@@ -140,7 +140,9 @@ our objects and in some error messages, for example::
 
 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 */
 
index 2f5688861a7199f22e91f30e2bec2696eb76cf4f..9c805b03e681451f71d93bdf134d5cacf8bc2d2f 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -733,6 +733,7 @@ Jeff Knupp
 Kubilay Kocak
 Greg Kochanski
 Manvisha Kodali
+Niklas Koep
 Damon Kohler
 Marko Kohtala
 Vajrasky Kok
index 1a737b84f83220ad1215a5dfa9e0168dfdce759b..ff55afe99f8d747f5bb5a5b6f8dc2f4f0db08f85 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.13?
 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.
 
index 950835c6b7681ba56b644e5944597c6b338bcd2a..f6d46632add51d04be296c15f76e92c415fa60fa 100644 (file)
@@ -4066,6 +4066,12 @@ PyType_Ready(PyTypeObject *type)
     _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) {