Skip to content

[3.8] bpo-37250: put back tp_print for backwards compatibility #14193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ typedef struct _typeobject {
destructor tp_finalize;
vectorcallfunc tp_vectorcall;

/* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);

#ifdef COUNT_ALLOCS
/* these must be last and never explicitly initialized */
Py_ssize_t tp_allocs;
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ def delx(self): del self.__x
check((1,2,3), vsize('') + 3*self.P)
# type
# static type: PyTypeObject
fmt = 'P2nPI13Pl4Pn9Pn11PIPP'
fmt = 'P2nPI13Pl4Pn9Pn11PIPPP'
if hasattr(sys, 'getcounts'):
fmt += '3n2P'
s = vsize(fmt)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``tp_print`` is put back at the end of the ``PyTypeObject`` structure
to restore support for old code (in particular generated by Cython)
setting ``tp_print = 0``.
Note that ``tp_print`` will be removed entirely in Python 3.9.
4 changes: 4 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6008,6 +6008,10 @@ PyInit__testcapi(void)
Py_INCREF(&MyList_Type);
PyModule_AddObject(m, "MyList", (PyObject *)&MyList_Type);

/* bpo-37250: old Cython code sets tp_print to 0, we check that
* this doesn't break anything. */
MyList_Type.tp_print = 0;

if (PyType_Ready(&MethodDescriptorBase_Type) < 0)
return NULL;
Py_INCREF(&MethodDescriptorBase_Type);
Expand Down