Skip to content

Commit f6d1b51

Browse files
Fixed the array module in unicode disabled build (regression of issue20014).
1 parent 79b13db commit f6d1b51

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/test/test_array.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def __init__(self, typecode, newarg=None):
1818
array.array.__init__(self, typecode)
1919

2020
tests = [] # list to accumulate all tests
21-
typecodes = "cubBhHiIlLfd"
21+
typecodes = "cbBhHiIlLfd"
22+
if test_support.have_unicode:
23+
typecodes += "u"
2224

2325
class BadConstructorTest(unittest.TestCase):
2426

@@ -837,6 +839,7 @@ def __repr__(self):
837839
self.assertEqual(s.color, "red")
838840
self.assertEqual(s.__dict__.keys(), ["color"])
839841

842+
@test_support.requires_unicode
840843
def test_nounicode(self):
841844
a = array.array(self.typecode, self.example)
842845
self.assertRaises(ValueError, a.fromunicode, unicode(''))

Modules/arraymodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,10 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19401940

19411941
if (PyString_Check(typecode) && PyString_GET_SIZE(typecode) == 1)
19421942
c = (unsigned char)*PyString_AS_STRING(typecode);
1943+
#ifdef Py_USING_UNICODE
19431944
else if (PyUnicode_Check(typecode) && PyUnicode_GET_SIZE(typecode) == 1)
19441945
c = *PyUnicode_AS_UNICODE(typecode);
1946+
#endif
19451947
else {
19461948
PyErr_Format(PyExc_TypeError,
19471949
"array() argument 1 or typecode must be char (string or "

0 commit comments

Comments
 (0)