Skip to content

Commit 975e928

Browse files
committed
[GR-12115] Unsupported specialization from array().
PullRequest: graalpython/238
2 parents 86d8d4d + e376bc8 commit 975e928

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def test_create():
6161
a = array('b', b'x' * 10)
6262
assert str(a) == "array('b', [120, 120, 120, 120, 120, 120, 120, 120, 120, 120])"
6363

64+
def test_wrong_create():
65+
from array import array
66+
raised = False
67+
try :
68+
a = array([1,2,3])
69+
except TypeError:
70+
raised = True
71+
assert raised
6472

6573
def test_add():
6674
from array import array

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ PArray arrayWithObjectInitializer(@SuppressWarnings("unused") PythonClass cls, @
244244
throw new RuntimeException("Unsupported initializer " + initializer);
245245
}
246246

247+
@Specialization(guards = "!isString(typeCode)")
248+
PArray noArray(@SuppressWarnings("unused") PythonClass cls, Object typeCode, @SuppressWarnings("unused") Object initializer) {
249+
throw raise(TypeError, "array() argument 1 must be a unicode character, not %p", typeCode);
250+
}
251+
247252
@TruffleBoundary
248253
private static long longValue(Number n) {
249254
return n.longValue();

0 commit comments

Comments
 (0)