Skip to content

Add the eager-runtime hook required by Python 3.15 importlib - #8946

Draft
youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-imp-lazy-attributes
Draft

youknowdot wants to merge 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-imp-lazy-attributes

Conversation

@youknowdot

Copy link
Copy Markdown

Summary

Add _imp._set_lazy_attributes(modobj, name, /), the private hook required by CPython 3.15 importlib after module loading.

In CPython v3.15.0rc2, this hook discards name from the pending lazy-module registry. RustPython currently executes imports eagerly and has no pending lazy entries. The implementation therefore validates the arguments and preserves string-subclass hashing (including exceptions), without modifying the module object.

This is a small native prerequisite for the target/site/importlib/test-support migration. It does not implement PEP 810 lazy imports. When a real lazy-module registry is introduced, this hook must remove the corresponding pending entry.

Only _imp.rs and one regression snippet change. The target version, bundled libraries, compiler, sentinel builtin, and cached import callback remain unchanged. The callback adjustment stays with the importlib migration, whose hierarchical-lock changes are needed for the concurrent-import cases.

Validation

Hook-only branch at 29d5ba99196b4a41c48946ee90ab762d5affa739:

  • Release build with SQLite enabled: passed
  • Source-isolation probe confirms unchanged Python 3.14 target, branch-local site/importlib/test.support, and the original cached import callback; no sentinel or compile(module=...) code is present
  • New hook snippet passes on RustPython and exact CPython 3.15.0rc2, including invalid argument types, positional-only use, string subclasses, surrogate names, and hash exceptions
  • -m test test_site test_support test_importlib test_pkgutil test_import --timeout 180: 1,676 run, 113 skipped; all five suites successful
  • Full bounded snippet aggregate: 469 passed, 13 failed. All failures match the unchanged environment/stress cases: ten AF_UNIX socket permission failures, two chown errno differences, and one CPython 3.14 GC/import timeout. RustPython's new hook case and GC/import stress case pass
  • Configured commit hooks and diff checks pass

The identical hook code also passed full Rust validation in the broader native-import candidate e2f1ed22366d258f4352e5ffaccebefa0bbfe467: workspace 1,345 passed/18 ignored, separate C-API 115 passed/4 ignored, and both all-targets Clippy commands clean. Those full Rust aggregates were not rerun after dropping the separate cached-importer change; the smaller branch was independently rebuilt and runtime-tested as above. No full Python 3.15 compatibility claim is made.

The snippet follows the existing skip_if_unsupported convention: every assertion always runs on RustPython; only the CPython comparison below 3.15 skips this unavailable API. It also runs separately against exact CPython 3.15.0rc2, commit 435c9e5a798c99653e3ab64ce29baed0e4f3dfee.

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. Reported checks are automated Linux x86_64 verification; no additional human-use or untested-platform validation is claimed.

Expose _imp._set_lazy_attributes(modobj, name, /), used by CPython 3.15 importlib after eager loading. Match its empty pending-lazy-module registry behavior, including name type and string-subclass hashing checks. This does not implement lazy imports or change the target version or bundled libraries.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this also in CPython 3.15's Lib/test directory? If so, it will eventually be migrated over to RustPython when RustPython begins targeting CPython 3.15.

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.

2 participants