Skip to content

Support compile(module=...) across AST warning paths - #8947

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-compile-module
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-compile-module

Conversation

@youknowdot

Copy link
Copy Markdown

Summary

Add Python 3.15's keyword-only compile(module=...) argument for SyntaxWarning filtering, including AST-only compilation and type comments. This is an independent native prerequisite for the 3.15 importlib/bootstrap migration; the advertised Python version and bundled libraries remain unchanged.

  • Validate module as str or None, keep diagnostic filenames separate, and preserve the existing Rust compile APIs through wrappers
  • Route existing AST format-spec diagnostics through a fallible, explicit-context boundary over the validated AST before preprocessing
  • Inspect literal spans so raw strings and comments do not become false SyntaxErrors, while nested nonraw warnings and distinct literals survive optimization
  • Map function-type argument/return fragments back to original source locations
  • Suppress duplicate TYPE_COMMENTS escape emissions using per-invocation offset tracking; warning callbacks can re-enter compile without sharing state
  • Preserve arbitrary warning-handler exceptions; convert escalated SyntaxWarning through the existing SyntaxError formatter

The implementation does not run a new whole-source warning scan before every AST parse or keep mutable warning context in VM-global/thread-local state.

Reference: CPython v3.15.0rc2, commit 435c9e5a798c99653e3ab64ce29baed0e4f3dfee. Its importlib source loader supplies this module context when compiling source.

Validation

Independent branch at a86db2711a26ece3781f39fea7b48c042f59bb3f:

  • Release build with SQLite enabled, source-isolation checks, and the expanded native regression snippet pass
  • The same snippet passes exact CPython 3.15.0rc2; its older-CPython comparison uses the existing version guard while RustPython always executes every assertion
  • -m test test_compile test_ast test_warnings test_site test_support test_importlib test_pkgutil --timeout 180: all seven suites successful, 2,156 run and 152 skipped
  • Independent 540-case differential corpus completed. Final membership cleanup produced byte-identical outputs to the reviewed candidate. 485 records match CPython exactly; 48 retain baseline detection/parser/traversal limitations and seven have the diagnostic differences below. All 180 optimization/folding controls match
  • Full bounded snippet aggregate: 469 passed, 13 failed. The failures are the unchanged executor/stress set: ten AF_UNIX socket permission failures, two chown errno differences, and one CPython 3.14 GC/import timeout. No new snippet failures
  • Workspace Rust tests: 1,345 passed, 18 ignored, no failures or warnings
  • Separate C-API tests: 115 passed, 4 ignored; workspace and separate C-API all-targets Clippy both passed without warnings
  • Normal configured commit hooks and diff checks pass

Remaining scope limits

This does not claim full compiler-warning parity. Existing missing warnings for ordinary AST-only literals and some ordinary-source/raw/template paths, and unrelated parser/traversal ordering, remain outside this change.

The shared diagnostic formatter also retains precise differences from CPython: three nested-template error cases point at the actual backslash rather than CPython's shifted position; three function-type cases append a newline to SyntaxError.text; one existing codegen case lacks end fields and differs in source text. These do not change module filtering, exception identity/type, valid-source acceptance, or duplicate suppression. They are recorded rather than hidden behind skips or CPython-specific caret adjustments.

AI assistance

OpenAI Codex assisted with implementation, CPython comparison, tests, review, and this description under maintainer direction. The runtime did not expose the exact model version. Results are automated Linux x86_64 verification; no additional human-use or untested-platform validation is claimed.

Add Python 3.15 compile(module=...) warning filtering. Move format-spec diagnostics to a fallible, literal-aware AST boundary; preserve nested literal warnings while excluding raw text and comments, map function-type fragments to source locations, and suppress duplicate type-comment emissions with per-call tracking.

Keep unrelated legacy warning-detection and exact diagnostic metadata gaps documented by differential probes. Add focused flag, source-location, exception, reentrancy, filtering and literal-boundary regression coverage.

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

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

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.

1 participant