mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
SF bug [#468061] __str__ ignored in str subclass.
object.c, PyObject_Str: Don't try to optimize anything except exact string objects here; in particular, let str subclasses go thru tp_str, same as non-str objects. This allows overrides of tp_str to take effect. stringobject.c: + string_print (str's tp_print): If the argument isn't an exact string object, get one from PyObject_Str. + string_str (str's tp_str): Make a genuine-string copy of the object if it's of a proper str subclass type. str() applied to a str subclass that doesn't override __str__ ends up here. test_descr.py: New str_of_str_subclass() test.
This commit is contained in:
parent
dfefc06fe0
commit
c993315b18
3 changed files with 52 additions and 8 deletions
|
@ -261,12 +261,6 @@ PyObject_Str(PyObject *v)
|
|||
Py_INCREF(v);
|
||||
return v;
|
||||
}
|
||||
if (PyString_Check(v)) {
|
||||
/* For a string subtype that's not a string, return a true
|
||||
string with the same string data. */
|
||||
PyStringObject *s = (PyStringObject *)v;
|
||||
return PyString_FromStringAndSize(s->ob_sval, s->ob_size);
|
||||
}
|
||||
if (v->ob_type->tp_str == NULL)
|
||||
return PyObject_Repr(v);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue