Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ def __index__(self):
assert False, "expected TypeError"


def test_int_from_unicode_whitespace():
# Py_UNICODE_ISSPACE includes NO-BREAK SPACE (U+00A0), unlike Java Character.isWhitespace
assert int("\xa0123") == 123
assert int("123\xa0") == 123



def test_create_int_from_float():
assert int(123.0) == 123
assert int(123.4) == 123
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -47,6 +47,7 @@
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
import com.oracle.graal.python.builtins.objects.ints.PInt;
import com.oracle.graal.python.builtins.objects.str.StringNodes;
import com.oracle.graal.python.builtins.objects.str.StringUtils;
import com.oracle.graal.python.nodes.ErrorMessages;
import com.oracle.graal.python.nodes.PRaiseNode;
import com.oracle.graal.python.nodes.util.CastToTruffleStringNode;
Expand Down Expand Up @@ -174,11 +175,12 @@ private static BigInteger asciiToBigInteger(Node inliningTarget, String str, int
int b = 0;
int e = str.length();

while (b < e && Character.isWhitespace(str.charAt(b))) {
// Py_UNICODE_ISSPACE / str.isspace, not Java Character.isWhitespace
while (b < e && StringUtils.isSpace(str.charAt(b))) {
b++;
}

while (e > b && Character.isWhitespace(str.charAt(e - 1))) {
while (e > b && StringUtils.isSpace(str.charAt(e - 1))) {
e--;
}

Expand Down