mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
More on SF bug [#460020] bug or feature: unicode() and subclasses.
Repaired str(i) to return a genuine string when i is an instance of a str subclass. New PyString_CheckExact() macro.
This commit is contained in:
parent
8ff70a9606
commit
5a49ade70e
4 changed files with 10 additions and 3 deletions
|
@ -250,10 +250,16 @@ PyObject_Str(PyObject *v)
|
|||
|
||||
if (v == NULL)
|
||||
return PyString_FromString("<NULL>");
|
||||
if (PyString_Check(v)) {
|
||||
if (PyString_CheckExact(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