PyObject_Print calls _Py_EnterRecursiveCall at line 639 but never calls _Py_LeaveRecursiveCall on the normal return path (line 691). Every successful call permanently increments the recursion depth counter. C API only — not directly callable from Python.
Add _Py_LeaveRecursiveCall(); before return ret; at line 691.