mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
(Adding this to the trunk as well.)
Fix a very old flaw in PyObject_Print(). Amazing! When an object type defines tp_str but not tp_repr, 'print x' to a real file object would not call the tp_str slot but rather print a default style representation: <foo object at 0x....>. This even though 'print x' to a file-like-object would correctly call the tp_str slot.
This commit is contained in:
parent
e9bcb5c766
commit
3a80c4a29c
1 changed files with 4 additions and 1 deletions
|
@ -196,7 +196,10 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
|
||||||
fprintf(fp, "<refcnt %u at %p>",
|
fprintf(fp, "<refcnt %u at %p>",
|
||||||
op->ob_refcnt, op);
|
op->ob_refcnt, op);
|
||||||
else if (op->ob_type->tp_print == NULL) {
|
else if (op->ob_type->tp_print == NULL) {
|
||||||
if (op->ob_type->tp_repr == NULL) {
|
if ((flags & Py_PRINT_RAW)
|
||||||
|
? (op->ob_type->tp_str == NULL)
|
||||||
|
: (op->ob_type->tp_repr == NULL))
|
||||||
|
{
|
||||||
fprintf(fp, "<%s object at %p>",
|
fprintf(fp, "<%s object at %p>",
|
||||||
op->ob_type->tp_name, op);
|
op->ob_type->tp_name, op);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue