Skip to content

Commit

Permalink
fix unicode test
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjekyejoannah committed May 1, 2024
1 parent 507db05 commit 93a383e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,13 @@ def __str__(self):
self.assertRaises(
TypeError,
unicode,
u"'decode()' is not supported on Unicode in 3.x: convert the string to bytes.",
u'decoding unicode is not supported',
'utf-8',
'strict'
)

self.assertEqual(
unicode("'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 'utf-8', 'strict'),
unicode('strings are decoded to unicode', 'utf-8', 'strict'),
u'strings are decoded to unicode'
)

Expand Down
28 changes: 20 additions & 8 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,17 +1211,29 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
#else
#endif

// if (PyUnicode_Check(obj)) {
// PyErr_SetString(PyExc_TypeError,
// "'decode()' is not supported on Unicode in 3.x: convert the string to bytes.");
// obj->ob_bstate = BSTATE_BYTE;
// if ((obj->ob_bstate == BSTATE_BYTE) &&
// PyErr_WarnPy3k(
// "'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
// return NULL;
// }
// return NULL;
// return PyObject_Unicode(obj);
// }

if (PyUnicode_Check(obj)) {
if (encoding) {
obj->ob_bstate = BSTATE_BYTE;
if ((obj->ob_bstate == BSTATE_BYTE) &&
PyErr_WarnPy3k(
"'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
return NULL;
}
obj->ob_bstate = BSTATE_BYTE;
if ((obj->ob_bstate == BSTATE_BYTE) &&
PyErr_WarnPy3k(
"'decode()' is not supported on Unicode in 3.x: convert the string to bytes.", 1) < 0) {
return NULL;
}
return PyObject_Unicode(obj);
PyErr_SetString(PyExc_TypeError,
"decoding Unicode is not supported");
return NULL;
}

/* Coerce object */
Expand Down

0 comments on commit 93a383e

Please sign in to comment.