]> git.ipfire.org Git - thirdparty/Python/cpython.git/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 2c448a0211799266602a6bbcda3d53c297326256..25e6c83153fcd30da5094e0d465d876703eac353 100644 (file)
@@ -116,7 +116,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 a69f114fe4c98b5b363589dc7fa89a1370723902..4a6e26cf2aac6153903a94879d6ca631762c6c87 100644 (file)
@@ -129,7 +129,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 6c1bafee18056471b513de57679af9f589f878db..d35f1e8916634f8eee627fb0827a0473f94a13cc 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -775,6 +775,7 @@ Jeff Knupp
 Kubilay Kocak
 Greg Kochanski
 Manvisha Kodali
+Niklas Koep
 Damon Kohler
 Marko Kohtala
 Vajrasky Kok
index 36a7f30a436cdb773deaa59e4cafe1303488535d..1b1c9d63dc245dbd5cd8c8e5ca14874d035e7dfd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
 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 e71b3f823172e0bb52444f8c5fe7647da1c30a1d..cbffecd5db3d8d7d024f93982774bbc24e0e7c2a 100644 (file)
@@ -4820,6 +4820,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) {