Skip to content
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

gh-98421: Clean Up PyObject_Print #98422

Merged
Merged
Changes from 1 commit
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
13 changes: 2 additions & 11 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,10 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
s = PyObject_Str(op);
else
s = PyObject_Repr(op);
if (s == NULL)
if (s == NULL) {
ret = -1;
else if (PyBytes_Check(s)) {
fwrite(PyBytes_AS_STRING(s), 1,
PyBytes_GET_SIZE(s), fp);
}
else if (PyUnicode_Check(s)) {
else {
PyObject *t;
MonadChains marked this conversation as resolved.
Show resolved Hide resolved
t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
encukou marked this conversation as resolved.
Show resolved Hide resolved
if (t == NULL) {
Expand All @@ -300,12 +297,6 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
Py_DECREF(t);
}
}
else {
PyErr_Format(PyExc_TypeError,
"str() or repr() returned '%.100s'",
Py_TYPE(s)->tp_name);
ret = -1;
}
Py_XDECREF(s);
MonadChains marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down