diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-11 03:07:38 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-11 03:07:38 (GMT) |
commit | 78e0fc74bce026ddf67d029030a90c9b8faffcb5 (patch) | |
tree | d66ea7c58d2630b08bf81f04e3d636a15b75314a /Objects | |
parent | 0ebeb584a496fec7a09bd62cb20ceb15cabde4e7 (diff) | |
download | cpython-78e0fc74bce026ddf67d029030a90c9b8faffcb5.zip cpython-78e0fc74bce026ddf67d029030a90c9b8faffcb5.tar.gz cpython-78e0fc74bce026ddf67d029030a90c9b8faffcb5.tar.bz2 |
Possibly the end of SF [#460020] bug or feature: unicode() and subclasses.
Changed unicode(i) to return a true Unicode object when i is an instance of
a unicode subclass. Added PyUnicode_CheckExact macro.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 98691fd..a50b925 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -425,12 +425,20 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj, } if (PyUnicode_Check(obj)) { if (encoding) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "decoding Unicode is not supported"); - return NULL; + return NULL; } - Py_INCREF(obj); - v = obj; + if (PyUnicode_CheckExact(obj)) { + Py_INCREF(obj); + v = obj; + } + else { + /* For a subclass of unicode, return a true unicode object + with the same string value. */ + v = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(obj), + PyUnicode_GET_SIZE(obj)); + } goto done; } else if (PyString_Check(obj)) { |