Skip to content

Commit fc3216d

Browse files
committed
GR-16509: fix calling int builtin with string big int arg
1 parent 88b1c14 commit fc3216d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def test_int_subclassing():
6262
assert str(MAXREPEAT) == "MAXREPEAT"
6363

6464

65+
def test_bigint():
66+
i = int(BIG_NUMBER)
67+
assert isinstance(i, int)
68+
assert i == BIG_NUMBER
69+
# from string
70+
i = int(str(BIG_NUMBER))
71+
assert isinstance(i, int)
72+
assert i == BIG_NUMBER
73+
74+
6575
def test_boolean2int():
6676
assert int(True) == 1
6777
assert int(False) == 0

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
87,
5151
1521583201331000000,
5252
1521583201347000000,
53-
10,
53+
10
5454
]
5555
}
5656
'''
5757

58+
5859
class JsonTest(unittest.TestCase):
5960
def test_dump(self):
6061
import json

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ public Object createInt(LazyPythonClass cls, String arg, @SuppressWarnings("unus
11251125
try {
11261126
Object value = stringToInt(arg, 10);
11271127
if (isPrimitiveInt(cls)) {
1128-
return value;
1128+
return value instanceof BigInteger ? factory().createInt(cls, (BigInteger) value) : value;
11291129
} else {
11301130
return value instanceof BigInteger ? factory().createInt(cls, (BigInteger) value) : factory().createInt(cls, (int) value);
11311131
}

0 commit comments

Comments
 (0)