Title: Support compile(module=...) across AST warning paths by youknowdot · Pull Request #8947 · RustPython/RustPython · GitHub
Open Graph Title: Support compile(module=...) across AST warning paths by youknowdot · Pull Request #8947 · RustPython/RustPython
X Title: Support compile(module=...) across AST warning paths by youknowdot · Pull Request #8947 · RustPython/RustPython
Description: This PR follows our AI policy 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. Python 3.15.0 final reference refresh (2026-10-09) The comparison target is now CPython v3.15.0 final, commit d220409a13b77de7a6c30abe16ea90db01528edc; the final importlib source loader supplies the module context. The upstream compile signature, module-context warning path, importlib source-loader caller, test_compile and test_warnings surfaces are unchanged from rc2. No native change is needed for this narrowly scoped contract. Adjacent parser and AST changes remain outside this PR's module-filtering scope. Fresh reference validation: the exact regression snippet at PR head 3cc5388b1e84a89dc42eef99dbfaf948afcd1d78 (extra_tests/snippets/builtin_compile_module.py) passed on exact CPython 3.15.0 final (exit 0; all assertions executed). This is a new CPython reference run only; the historical rc2 differential corpus, RustPython results and documented parity limits above remain unchanged. Hosted checks for that unchanged PR head were rechecked on this date: all reported checks are terminal success or skipped; no pending or failed checks were reported. 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. Summary by CodeRabbit New Features Added an optional keyword-only module argument to compile(). Its value is included in compiler warning messages, while source filenames remain unchanged. Invalid escape warnings in format specifications are now reported during parsing. Bug Fixes Prevented duplicate invalid escape warnings across parsing and compilation. Invalid values for module now raise a TypeError.
Open Graph Description: This PR follows our AI policy Summary Add Python 3.15's keyword-only compile(module=...) argument for SyntaxWarning filtering, including AST-only compilation and type comments. This is an inde...
X Description: This PR follows our AI policy Summary Add Python 3.15's keyword-only compile(module=...) argument for SyntaxWarning filtering, including AST-only compilation and type comments. This is an ...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8947
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4f3001fe-43aa-73f7-7dea-e75cdb36fc56 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CAF4:3E418A:121F5D5:17DBC80:6B01E691 |
| html-safe-nonce | 8b737482cc1ff1c8a0f4045bf6d722eb5ddedd7d056f1433781cfcfbccdaa032 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUY0OjNFNDE4QToxMjFGNUQ1OjE3REJDODA6NkIwMUU2OTEiLCJ2aXNpdG9yX2lkIjoiMzQ3OTQxOTAyMTkzMjIyNjE5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e9f7fced984a07399a6c8a8c328064b4c4cf87a66757f8a9977862d5b39e81a3 |
| hovercard-subject-tag | pull_request:4718203915 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8947/files |
| twitter:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| og:image:alt | This PR follows our AI policy Summary Add Python 3.15's keyword-only compile(module=...) argument for SyntaxWarning filtering, including AST-only compilation and type comments. This is an inde... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width