summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-11 01:41:59 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-11 01:41:59 (GMT)
commit5a49ade70e19a76aa252cd596accf79930765f31 (patch)
treeab54e1ff25892e49fbb483ba4e461f30763e1fc6 /Objects/object.c
parent8ff70a9606aa2f51f8329fbf09dfbbbae6ab6c11 (diff)
downloadcpython-5a49ade70e19a76aa252cd596accf79930765f31.zip
cpython-5a49ade70e19a76aa252cd596accf79930765f31.tar.gz
cpython-5a49ade70e19a76aa252cd596accf79930765f31.tar.bz2
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.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 704ffc1..718dddf 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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);