Skip to content

Set sys.flags.debug to 0 by default - #1219

Draft
hippi345 wants to merge 1 commit into
oracle:masterfrom
hippi345:fix/1213-sys-flags-debug
Draft

hippi345 wants to merge 1 commit into
oracle:masterfrom
hippi345:fix/1213-sys-flags-debug

Conversation

@hippi345

@hippi345 hippi345 commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

CPython keeps sys.flags.debug at 0 unless -d is given. GraalPy was initializing that field from !PythonOptimizeFlag, so the default value was 1.

This change sets sys.flags.debug to 0 and adds a GraalPy unittest that asserts the default.

Fixes #1213

Test plan

  1. Add SysFlagsTests.test_debug_is_zero_by_default on unmodified upstream/master.
  2. mx --java-home=lookup:default python-jvm && mx --java-home=lookup:default graalpytest test_sys.py — fails (1 != 0).
  3. Set the debug field to 0 in SysModuleBuiltins.java.
  4. Rebuild and rerun test_sys.py — passes.
  5. Nearby sys tests: mx --java-home=lookup:default graalpytest test_sys.py test_sysconfig.py test_sys_settrace.py — passes.

Before (unmodified SysModuleBuiltins, new test only)

===== BEFORE (unmodified SysModuleBuiltins) =====
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_sys.py '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 3 tests
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.SysFlagsTests.test_debug_is_zero_by_default ... FAIL (0.08s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_java_backend ... skipped 'Windows only'
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_matches_os ... skipped 'Windows only'

======================================================================
FAIL: graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.SysFlagsTests.test_debug_is_zero_by_default
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspace/graalpython/com.oracle.graal.python.test/src/tests/test_sys.py", line 141, in test_debug_is_zero_by_default
    self.assertEqual(sys.flags.debug, 0)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
AssertionError: 1 != 0

Ran 3 tests in 0.11s

FAILED (failures=1, skipped=2)
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_sys.py '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3' returned non-zero exit status 1.
===== BEFORE EXIT=1 =====

After (debug hardcoded to 0)

===== AFTER (debug hardcoded to 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_sys.py '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 3 tests
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.SysFlagsTests.test_debug_is_zero_by_default ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_java_backend ... skipped 'Windows only'
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_matches_os ... skipped 'Windows only'

Ran 3 tests in 0.03s

OK (passed=1, skipped=2)
===== AFTER test_sys EXIT=0 =====

Nearby sys tests

===== NEARBY SYS 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_sys.py test_sysconfig.py test_sys_settrace.py '--subprocess-args=--experimental-options=true --python.EnableDebuggingBuiltins' --append-path=/workspace/graalpython/lib-python/3
Collected 52 tests
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.SysFlagsTests.test_debug_is_zero_by_default ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_java_backend ... skipped 'Windows only'
graalpython/com.oracle.graal.python.test/src/tests/test_sys.py::tests.test_sys.WindowsVersionTests.test_getwindowsversion_matches_os ... skipped 'Windows only'
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_sysconfig ... ok (0.01s)
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_platform_sysconfigdata ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_tzpath_searches_system_time_zones ... ok (3.06s)
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_windows_libpython_is_not_exposed ... skipped 'Windows-specific sysconfig behavior'
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_windows_hash_algorithm ... skipped 'Windows-specific sysconfig behavior'
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_windows_library_names ... skipped 'Windows-specific sysconfig behavior'
graalpython/com.oracle.graal.python.test/src/tests/test_sysconfig.py::test_windows_platform_specific_sys_attributes ... skipped 'Windows-specific sysconfig behavior'
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.AnnotationsEvents.test_multiple_fun_annotations ... ok (0.16s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.AsyncTracingEventsUnitTest.test_01_await ... skipped 'GR-65570: GraalPy does not report await exception trace events yet.'
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.AsyncTracingEventsUnitTest.test_02_async_with ... skipped 'GR-65570: GraalPy does not report async with exception trace events yet.'
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.AsyncTracingEventsUnitTest.test_03_async_for ... skipped 'GR-65570: GraalPy does not match CPython async for trace events yet.'
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_01_except_star_with_name ... ok (0.01s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_02_except_star_multi_with_name ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_03_except_star_with_finally ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_04_test_try_except_star_with_wrong_type ... skipped 'TODO: Fix return in finally.'
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_05_if_false_in_try_except_star ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_06_try_in_try_with_exception ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_07_tracing_exception_raised_in_with ... skipped "TODO: Isn't even tagged from CPython tests."
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_08_try_except_star_no_exception ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_09_try_except_star_named_no_exception ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_10_try_except_star_exception_caught ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_11_try_except_star_named_exception_caught ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_12_try_except_star_exception_not_caught ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_13_try_except_star_named_exception_not_caught ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.ExceptStarTraceTest.test_14_try_except_star_nested ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_01_multiline_call_method_basic ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_02_multiline_call_method_vargs ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_03_multiline_call_function_basic ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_04_multiline_call_function_vargs ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_05_multiline_call_function_fallback_to_vargs ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_06_multiline_binop ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_07_multiline_boolop ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.MultilineCallsTraceTest.test_08_multiline_boolop_short ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.SingleLineMultipleStmts.test_01_if_elif_else ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.SingleLineMultipleStmts.test_02_if_elif_else_implicit_return ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_01_basic ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_02_more_complex ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_04_two_functions ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_05_generator_example ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_05_generator_same_line_example ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_06_f_trace_preserved ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_07_async_actions_not_traced ... ok (0.06s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTests.test_08_frame_f_trace_deletable ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtTry.test_01_reraise ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtWith.test_01_break_in_with ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtWith.test_02_if_false_in_with_multiple_nested ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtWith.test_03_break_in_with_nested ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtWith.test_04_except_in_with ... ok (0.00s)
graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py::tests.test_sys_settrace.TraceTestsStmtWith.test_05_except_in_with_nested ... ok (0.00s)

Ran 52 tests in 3.45s

OK (passed=41, skipped=11)
===== NEARBY EXIT=0 =====

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

CPython reports sys.flags.debug as 0 unless -d is given. GraalPy
was setting it from the inverse of PythonOptimizeFlag, so the
default value was 1.

Fixes oracle#1213

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]: sys.flags.debug is 1 whenever optimization is off

1 participant