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:
Tim Peters 2001-09-11 01:41:59 +00:00
parent 8ff70a9606
commit 5a49ade70e
4 changed files with 10 additions and 3 deletions

View file

@ -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);