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

Skip to content

Commit de0574b

Browse files
Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
Original patch by Niklas Koep.
1 parent 8793b21 commit de0574b

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
@@ -775,6 +775,7 @@ Jeff Knupp
775775
Kubilay Kocak
776776
Greg Kochanski
777777
Manvisha Kodali
778+
Niklas Koep
778779
Damon Kohler
779780
Marko Kohtala
780781
Vajrasky Kok

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
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
@@ -4820,6 +4820,12 @@ PyType_Ready(PyTypeObject *type)
48204820
_Py_AddToAllObjects((PyObject *)type, 0);
48214821
#endif
48224822

4823+
if (type->tp_name == NULL) {
4824+
PyErr_Format(PyExc_SystemError,
4825+
"Type does not define the tp_name field.");
4826+
goto error;
4827+
}
4828+
48234829
/* Initialize tp_base (defaults to BaseObject unless that's us) */
48244830
base = type->tp_base;
48254831
if (base == NULL && type != &PyBaseObject_Type) {

0 commit comments

Comments
 (0)