mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
0ebeb584a4
commit
78e0fc74bc
3 changed files with 16 additions and 6 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue