Skip to content

Use __main__ for filesystem script compiler warnings - #9301

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:py315-script-warning-main-module
Oct 22, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:py315-script-warning-main-module

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pass __main__ to the module-aware compiler when executing a filesystem source script. Previously, -Walways:::__main__ could not override -Werror for those compiler warnings, causing a valid script to fail with SyntaxError: invalid decimal literal.

This extracts the script-warning fix from #8954 using the typed compiler wrapper preserved by #9294. It does not change warning ordering, execution globals, bytecode loading, run_string, or zip/runpy execution.

Sync Lib/test/test_cmd_line_script.py with scripts/update_lib migrate from CPython d220409a13b77de7a6c30abe16ea90db01528edc. The resulting file matches the mega branch and retains the existing Android/Linux test_non_ascii expected-failure adaptation. No assertions or expected warning counts were weakened.

Validation

Tested on 1ba110711575d65bb64e85d4e302fd2a8a105887; the patch also merges cleanly with current main eb03691084b0366381405ba732cf5ebd0e5518b0. The merged #9296 compiler-ordering change was reviewed for source composition, but this combined tree has not been locally executed.

  • Default CLI build with capi passed.
  • Candidate: all eight selected canonical tests passed. Baseline: seven passed; only the ordinary-file module-filter test failed as expected.
  • The unchanged six-warning ordinary-file assertion, twelve-warning zip assertion, and six compiled script/directory/zip/package controls were exercised without skips or expected failures.
  • Subprocess tests were directly supervised, not traced. Configured commit hooks passed.

VM checks passed with default host-environment features plus threading, and with --no-default-features --features compiler. VM all-targets Clippy with threading and -D warnings passed. Full workspace/C-API test suites and Windows/macOS/mobile/non-host-environment runtime testing were not run. The runtime comparison uses the stated base, not a claim that all current-main library changes were tested.

AI assistance: implementation, source review, and validation were assisted by OpenAI Codex; the commit includes an Assisted-by trailer.

Summary by CodeRabbit

  • Improvements
    • Running Python source files now respects the virtual machine’s compilation settings and executes them in the main-module context. This provides more consistent behavior when scripts are run through the VM, while compilation failures continue to be reported as Python exceptions with the source attached.

Forward script compiler warnings through the typed module-aware entry point. Sync canonical command-line script coverage from CPython d220409a13b77de7a6c30abe16ea90db01528edc with the existing RustPython marker preserved.

Assisted-by: OpenAI Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between eb03691 and a0c88bf.

⛔ Files ignored due to path filters: 1
  • Lib/test/test_cmd_line_script.py is excluded by !Lib/**
📒 Files selected for processing: 1
  • crates/vm/src/vm/python_run.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

File execution now compiles source with the VM’s compile options, the __main__ module, and an empty extra-arguments slice. Compilation errors still become Python exceptions with the source attached.

Changes: File execution

Layer / File(s) Summary
Compile files with VM options
crates/vm/src/vm/python_run.rs
run_simple_file_inner now calls compile_with_opts_and_module with the VM’s compile options, __main__, and an empty extra-arguments slice. Compilation errors are still converted to Python exceptions with the source attached.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: shaharnaveh

Merge Risk: ⚪ Minimal · up to a0c88

The change is mergeable with no identified current-head risk requiring resolution.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: passing main to the filesystem script compiler to control compiler warnings.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_bytes.py (TODO: 12)

dependencies:

dependent tests: (no tests depend on bytes)

[x] test: cpython/Lib/test/test_cmd_line_script.py (TODO: 1)

dependencies:

dependent tests: (no tests depend on cmd_line_script)

[ ] lib: cpython/Lib/bdb.py
[x] test: cpython/Lib/test/test_bdb.py (TODO: 1)

dependencies:

  • bdb (native: main, sys)
    • contextlib, dis, fnmatch, functools, inspect, linecache, os, reprlib, threading, weakref

dependent tests: (2 tests)

  • bdb: test_bdb test_pdb

[ ] lib: cpython/Lib/modulefinder.py
[ ] test: cpython/Lib/test/test_modulefinder.py

dependencies:

  • modulefinder (native: importlib._bootstrap_external, importlib.machinery, marshal, sys)
    • io (native: _io, _thread, errno, msvcrt, sys)
    • dis, getopt, os

dependent tests: (2 tests)

  • modulefinder: test_importlib test_modulefinder

[ ] lib: cpython/Lib/pdb.py
[ ] test: cpython/Lib/test/test_pdb.py (TODO: 30)

dependencies:

  • pdb (native: main, _pyrepl.main, _pyrepl.readline, _pyrepl.simple_interact, _pyrepl.utils, atexit, builtins, itertools, readline, sys)
    • asyncio (native: _asyncio, _overlapped, _pyrepl.console, _pyrepl.main, _pyrepl.simple_interact, _remote_debugging, _winapi, asyncio.tools, base_events, collections.abc, concurrent.futures, coroutines, errno, events, exceptions, futures, graph, itertools, locks, log, math, msvcrt, protocols, queues, readline, runners, streams, sys, taskgroups, tasks, threads, time, timeouts, transports, unix_events, windows_events)
    • codeop
    • pydoc (native: _pyrepl.pager, builtins, email.message, http.server, importlib._bootstrap, importlib._bootstrap_external, importlib.machinery, importlib.util, pydoc_data.topics, select, sys, time, urllib.parse)
    • bdb, io
    • _colorize, argparse, cmd, code, contextlib, dis, glob, inspect, json, linecache, os, pprint, re, rlcompleter, runpy, selectors, shlex, signal, socket, stat, tempfile, textwrap, threading, token, tokenize, traceback, types, typing, warnings, weakref

dependent tests: (1 tests)

  • pdb: test_pdb

[ ] lib: cpython/Lib/codeop.py
[x] test: cpython/Lib/test/test_codeop.py

dependencies:

  • codeop

dependent tests: (112 tests)

  • codeop: test_codeop
    • code:
      • pdb: test_pdb
      • sqlite3.main: test_sqlite3
    • traceback: test_asyncio test_builtin test_code_module test_concurrent_futures test_contextlib test_contextlib_async test_coroutines test_dictcomps test_exceptions test_http_cookiejar test_importlib test_iter test_listcomps test_pyexpat test_setcomps test_socket test_ssl test_subprocess test_sys test_threadedtempfile test_threading test_traceback test_unittest test_with test_zipimport
      • concurrent.futures.interpreter: test_concurrent_futures
      • concurrent.futures.process: test_compileall test_concurrent_futures
      • http.cookiejar: test_urllib2
      • logging: test_asyncio test_decimal test_genericalias test_hashlib test_logging test_pkgutil test_support test_unittest test_urllib2net
      • multiprocessing: test_asyncio test_concurrent_futures test_fcntl test_importlib test_memoryview test_multiprocessing_forkserver test_multiprocessing_main_handling test_profiling test_re
      • py_compile: test_cmd_line_script test_importlib test_modulefinder test_py_compile test_pydoc test_runpy
      • pydoc: test_enum
      • site: test_site
      • socketserver: test_imaplib test_socketserver test_wsgiref
      • threading: test_android test_asyncio test_bytes test_bz2 test_code test_concurrent_futures test_context test_ctypes test_docxmlrpc test_email test_enumerate test_external_inspection test_fork1 test_frame test_ftplib test_functools test_gc test_httplib test_httpservers test_importlib test_inspect test_io test_ioctl test_itertools test_linecache test_opcache test_pathlib test_poll test_poplib test_pyrepl test_queue test_robotparser test_sched test_signal test_smtplib test_sqlite3 test_super test_syslog test_termios test_threading_local test_time test_urllib2_localnet test_weakref test_winreg test_xmlrpc test_zstd
      • timeit: test_timeit
      • tkinter: test_pyrepl test_tkinter test_ttk test_ttk_textonly

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@codspeed

codspeed Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 11.01%

⚡ 1 improved benchmark
✅ 61 untouched benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ rustpython[comprehension_list.py] 892.8 µs 804.3 µs +11.01%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing youknowdot:py315-script-warning-main-module (a0c88bf) with main (eb03691)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 22, 2026 11:44
@youknowone
youknowone enabled auto-merge (squash) October 22, 2026 11:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T11:49:35.017459Z a0c88bf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0c88bfdfc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
py_compile.compile(script_name, doraise=True)
pyc_file = import_helper.make_legacy_pyc(script_name, allow_compile=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revert non-marker edits to the regression tests

This helper replacement rewrites an existing regression test's compilation setup, and the commit repeats the same non-marker edit in other test bodies. The repository's test policy explicitly forbids modifying test logic and permits only expected-failure marker changes, so revert these body edits and keep the functional change in Rust.

AGENTS.md reference: AGENTS.md:L278-L282

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit 0b0a360 into RustPython:main Oct 22, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants