Skip to content

Honor Py_UNICODE_ISSPACE when parsing int() from strings - #1220

Draft
hippi345 wants to merge 1 commit into
oracle:masterfrom
hippi345:fix/1209-int-unicode-whitespace
Draft

hippi345 wants to merge 1 commit into
oracle:masterfrom
hippi345:fix/1209-int-unicode-whitespace

Conversation

@hippi345

@hippi345 hippi345 commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

int() string parsing in PyLongFromUnicodeObject stripped leading/trailing whitespace with Java Character.isWhitespace. That does not match CPython Py_UNICODE_ISSPACE / str.isspace (for example U+00A0 NO-BREAK SPACE is a Python space but not a Java whitespace character).

This change reuses StringUtils.isSpace, the same helper used by str.isspace, when stripping int() input.

Fixes #1209

Tests

New coverage in test_int.py:

  • int("\xa0123") == 123
  • int("123\xa0") == 123

Before (unmodified upstream/master, new test only)

========== BEFORE FIX: new test only ==========
WARNING:   graalpython:PYTHON_NATIVE_STANDALONE_SVM_JAVA25:
distribution PYTHON_NATIVE_STANDALONE_SVM_JAVA25 redefined
Running: MX_GRAALPYTEST=1 PYTHONHASHSEED=0 /workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_int_from_unicode_whitespace '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 1 tests
graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_int_from_unicode_whitespace ... ERROR (0.10s)

======================================================================
ERROR: graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_int_from_unicode_whitespace
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspace/graalpython/com.oracle.graal.python.test/src/tests/test_int.py", line 456, in test_int_from_unicode_whitespace
    assert int("\xa0123") == 123
           ~~~^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '\xa0123'

Ran 1 tests in 0.13s

FAILED (errors=1)
Command '/workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_int_from_unicode_whitespace '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3' returned non-zero exit status 1.
EXIT=1

After (fix + nearby int tests)

========== AFTER FIX: new test + nearby int tests ==========
WARNING:   graalpython:PYTHON_NATIVE_STANDALONE_SVM_JAVA25:
distribution PYTHON_NATIVE_STANDALONE_SVM_JAVA25 redefined
Running: MX_GRAALPYTEST=1 PYTHONHASHSEED=0 /workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_int_from_unicode_whitespace '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 1 tests
graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_int_from_unicode_whitespace ... ok (0.00s)

Ran 1 tests in 0.02s

OK (passed=1)
NEW_TEST_EXIT=0
WARNING:   graalpython:PYTHON_NATIVE_STANDALONE_SVM_JAVA25:
distribution PYTHON_NATIVE_STANDALONE_SVM_JAVA25 redefined
Running: MX_GRAALPYTEST=1 PYTHONHASHSEED=0 /workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_create_int_from_string '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 1 tests
graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_create_int_from_string ... ok (0.00s)

Ran 1 tests in 0.02s

OK (passed=1)
NEARBY_TEST_EXIT=0
WARNING:   graalpython:PYTHON_NATIVE_STANDALONE_SVM_JAVA25:
distribution PYTHON_NATIVE_STANDALONE_SVM_JAVA25 redefined
Running: MX_GRAALPYTEST=1 PYTHONHASHSEED=0 /workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_create_int_from_float '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 1 tests
graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_create_int_from_float ... ok (0.00s)

Ran 1 tests in 0.02s

OK (passed=1)
NEARBY2_EXIT=0
WARNING:   graalpython:PYTHON_NATIVE_STANDALONE_SVM_JAVA25:
distribution PYTHON_NATIVE_STANDALONE_SVM_JAVA25 redefined
Running: MX_GRAALPYTEST=1 PYTHONHASHSEED=0 /workspace/mxbuild/linux-amd64/GRAALPY_JVM_STANDALONE/bin/graalpy --vm.ea --python.WithJavaStacktrace=1 --experimental-options=true --python.EnableDebuggingBuiltins /workspace/graalpython/com.oracle.graal.python.test/src/runner.py run test_int.py::test_int '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 1 tests
graalpython/com.oracle.graal.python.test/src/tests/test_int.py::test_int ... ok (0.00s)

Ran 1 tests in 0.03s

OK (passed=1)
TEST_INT_EXIT=0

This change was prepared with AI assistance. I remain responsible for the contribution and have reviewed it.

int() stripping now uses StringUtils.isSpace (str.isspace /
Py_UNICODE_ISSPACE) so characters such as U+00A0 are accepted.

Fixes oracle#1209

Signed-off-by: hippi345 <13539685+hippi345@users.noreply.github.com>
@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: incompatible (wrt CPython int's) processing of strings by int() constructor with spaces

1 participant