Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e45b7c0

Browse files
Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
Original patch by Niklas Koep.
2 parents 242c170 + de0574b commit e45b7c0

5 files changed

Lines changed: 15 additions & 2 deletions

File tree

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ type objects) *must* have the :attr:`ob_size` field.
116116
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
117117
:attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined
118118
(unless explicitly set in the dictionary, as explained above). This means your
119-
type will be impossible to pickle.
119+
type will be impossible to pickle. Additionally, it will not be listed in
120+
module documentations created with pydoc.
120121

121122
This field is not inherited by subtypes.
122123

Doc/extending/newtypes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ our objects and in some error messages, for example::
129129

130130
Note that the name is a dotted name that includes both the module name and the
131131
name of the type within the module. The module in this case is :mod:`noddy` and
132-
the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`. ::
132+
the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`.
133+
One side effect of using an undotted name is that the pydoc documentation tool
134+
will not list the new type in the module documentation. ::
133135

134136
sizeof(noddy_NoddyObject), /* tp_basicsize */
135137

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ Jeff Knupp
783783
Kubilay Kocak
784784
Greg Kochanski
785785
Manvisha Kodali
786+
Niklas Koep
786787
Damon Kohler
787788
Marko Kohtala
788789
Vajrasky Kok

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
14+
Original patch by Niklas Koep.
15+
1316
- Issue #24098: Fixed possible crash when AST is changed in process of
1417
compiling it.
1518

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4893,6 +4893,12 @@ PyType_Ready(PyTypeObject *type)
48934893
_Py_AddToAllObjects((PyObject *)type, 0);
48944894
#endif
48954895

4896+
if (type->tp_name == NULL) {
4897+
PyErr_Format(PyExc_SystemError,
4898+
"Type does not define the tp_name field.");
4899+
goto error;
4900+
}
4901+
48964902
/* Initialize tp_base (defaults to BaseObject unless that's us) */
48974903
base = type->tp_base;
48984904
if (base == NULL && type != &PyBaseObject_Type) {

0 commit comments

Comments
 (0)