Fixed the array module in unicode disabled build (regression of issue20014).

This commit is contained in:
Serhiy Storchaka 2015-05-31 11:56:48 +03:00
parent 062bed289b
commit dc967c137c
2 changed files with 6 additions and 1 deletions

View File

@ -18,7 +18,9 @@ class ArraySubclassWithKwargs(array.array):
array.array.__init__(self, typecode) array.array.__init__(self, typecode)
tests = [] # list to accumulate all tests tests = [] # list to accumulate all tests
typecodes = "cubBhHiIlLfd" typecodes = "cbBhHiIlLfd"
if test_support.have_unicode:
typecodes += "u"
class BadConstructorTest(unittest.TestCase): class BadConstructorTest(unittest.TestCase):
@ -837,6 +839,7 @@ class CharacterTest(StringTest):
self.assertEqual(s.color, "red") self.assertEqual(s.color, "red")
self.assertEqual(s.__dict__.keys(), ["color"]) self.assertEqual(s.__dict__.keys(), ["color"])
@test_support.requires_unicode
def test_nounicode(self): def test_nounicode(self):
a = array.array(self.typecode, self.example) a = array.array(self.typecode, self.example)
self.assertRaises(ValueError, a.fromunicode, unicode('')) self.assertRaises(ValueError, a.fromunicode, unicode(''))

View File

@ -1940,8 +1940,10 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (PyString_Check(typecode) && PyString_GET_SIZE(typecode) == 1) if (PyString_Check(typecode) && PyString_GET_SIZE(typecode) == 1)
c = (unsigned char)*PyString_AS_STRING(typecode); c = (unsigned char)*PyString_AS_STRING(typecode);
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(typecode) && PyUnicode_GET_SIZE(typecode) == 1) else if (PyUnicode_Check(typecode) && PyUnicode_GET_SIZE(typecode) == 1)
c = *PyUnicode_AS_UNICODE(typecode); c = *PyUnicode_AS_UNICODE(typecode);
#endif
else { else {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"array() argument 1 or typecode must be char (string or " "array() argument 1 or typecode must be char (string or "