GeezerVison is showing github.com — Preserve function metadata and annotation callback lifetimes by youknowdot · Pull Request #9162 · RustPython/RustPython
Conversation
Summary
Align function/type/module metadata contracts with CPython 3.15 final, with explicit publication and cleanup order when annotation callbacks or finalizers re-enter Python.
- Preserve the original code-name object when constructing a function without a name; accept explicit
None as omitted while retaining explicit string/subclass behavior.
- Copy the standard metadata onto implicit
__new__, __init_subclass__, and __class_getitem__ wrappers using the existing wrapping helper.
- Match annotation dict-subclass acceptance and qualified invalid-result diagnostics. Publish annotation/cache changes in CPython's observable phases, retain displaced Python owners until after releasing locks, and release callbacks before the corresponding validation/cache steps. Deleting function annotations also clears its annotator.
- Register slice's existing GenericAlias implementation.
- Migrate the complete
test_type_annotations.py and test_genericalias.py files through scripts/update_lib from CPython d220409a13b77de7a6c30abe16ea90db01528edc. No hand-edited assertions or removed capability guards.
This is a bounded decomposition of #8954, with independently checked callback/finalizer ordering, rather than a wholesale copy of its type implementation.
Base and prerequisite
Based on main fd5b30eb5e6c1dd24bb98a305b1c5f47fa64820d, verified again on 2026-10-16. The branch includes the exact separate bf076f10c503749521d176b9b757fe5b3088fe63 benchmark import fix from #9161, which is still open and needed for strict all-target lint. The metadata changes are the following two commits, ending at 3d8adae764d7db2cf593fa58b61f658043970ecd. The prerequisite should disappear from the PR comparison once #9161 is merged/reconciled.
Validation
Fresh Linux validation at the exact source above:
- Normal repository commit hooks passed. Independent source review covered ownership release, callback re-entry, cache publication and canonical test provenance.
cargo clippy --offline --locked -p rustpython -p rustpython-vm --all-targets -- -D warnings passed.
cargo build --offline --locked -p rustpython --bin rustpython passed. This is a default-feature debug build, with two jobs, debug info disabled and incremental compilation disabled. Workspace artifacts, including pylib, were refreshed before building.
- Candidate: 36 selectors, each running exactly one unittest test, all 36 passed. These comprise 13 selected repository canonical methods, the complete canonical
BaseTest.test_subscriptable method (all of its original parameters, including slice), one separately loaded unchanged canonical descriptor method, six supplemental metadata observations and 15 separately isolated finalizer/re-entry observations.
- Reference: the same six metadata and 15 finalizer observations passed first on the installed official CPython 3.15.0 final runtime. Its exact executable/library hashes were pinned; its build commit is not asserted to be d220. The C source and migrated test references are separately pinned to d220.
- Both groups had zero failures, errors, skips, expected failures or unexpected successes. Canonical capability checks and assertions were retained. Successful parameter subtests are not reported as extra unittest tests.
Each case ran in a fresh bounded process with verified actual module origins and the sealed executable. Candidate binary SHA-256: f8039c49f9e9c61380c9763eff1af4e1e0c19719b45c84714b33e94f89e992f0.
Limits
The two canonical files were migrated whole, but no complete canonical test module was executed locally. The GenericAlias result is the full selected method, not the full module. The unchanged external descriptor method and supplemental observations are separate evidence, not additional committed test-file migrations. Full workspace/C-API suites, other platforms, concurrency stress and broad GC/lifetime correctness were not validated by this packet. No broad type-layout, C-API or GC redesign is included.
AI assistance
OpenAI Codex assisted with implementation, independent source review, canonical migration, validation and this draft under maintainer direction. Commit trailers disclose assistance.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Use the canonical code module path introduced in PyO3 0.30 without suppressing deprecation warnings.
Assisted-by: OpenAI Codex:model version unavailable
Preserve function name identity, implicit wrapper metadata and slice generic aliases. Match annotation dictionary and reentrant publication contracts, releasing displaced Python owners outside locks in the required phases. Refresh the matching canonical annotation tests through update_lib.
Assisted-by: OpenAI Codex: gpt-6.1-sol
Migrate the complete Python 3.15 test_genericalias file through update_lib. Preserve the full canonical type list and capability guards so normal test runs cover slice subscripting.
Assisted-by: OpenAI Codex: gpt-6.1-sol
coderabbitai
Bot
commented
Oct 16, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Note Currently processing new changes in this PR. This may take a few minutes, please wait...
⚙️ Run configuration
-
- Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ec3a8eb3-1d49-4514-928a-769b91c507e1
📥 Commits
-
Reviewing files that changed from the base of the PR and between fd5b30e and 3d8adae.
⛔ Files ignored due to path filters: 2
-
Lib/test/test_genericalias.py is excluded by !Lib/**
Lib/test/test_type_annotations.py is excluded by !Lib/**
📒 Files selected for processing: 5
-
benches/execution.rs
crates/vm/src/builtins/function.rs
crates/vm/src/builtins/module.rs
crates/vm/src/builtins/slice.rs
crates/vm/src/builtins/type.rs
+------------------------------------------+
| Given enough GPUs, all bugs are shallow. |
+------------------------------------------+
\
\ /)/)
( '')
/ |
o(___)
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
📦 Library Dependencies
The following Lib/ modules were modified. Here are their dependencies:
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[ ] lib: cpython/Lib/typing.py
[ ] test: cpython/Lib/test/test_typing.py (TODO: 1)
[ ] test: cpython/Lib/test/test_type_aliases.py
[x] test: cpython/Lib/test/test_type_annotations.py
[x] test: cpython/Lib/test/test_type_params.py
[x] test: cpython/Lib/test/test_genericalias.py
dependencies:
- typing (native: _typing, collections.abc, sys)
- annotationlib (native: builtins, sys)
- collections (native: _collections, _weakref, itertools, sys)
- contextlib (native: sys)
- inspect (native: _weakref, builtins, collections.abc, importlib.machinery, itertools, sys)
- re (native: _casefix, _constants, _sre, sys, unicodedata)
- types (native: _types, sys)
- abc, copyreg, functools, operator, warnings
dependent tests: (19 tests)
- typing: test_annotationlib test_builtin test_copy test_enum test_fractions test_funcattrs test_functools test_genericalias test_grammar test_inspect test_isinstance test_patma test_peg_generator test_pydoc test_pyrepl test_type_aliases test_type_params test_types test_typing
Legend:
[+] path exists in CPython
[x] up-to-date, [ ] outdated
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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-16T14:54:05.007390Z |
3d8adae |
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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: 3d8adae764
ℹ️ 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".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+103
to
+105
|
|
generic_types = [type, tuple, list, dict, frozendict,
|
|
|
set, frozenset, enumerate, memoryview,
|
|
|
slice,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes to generic-alias test data
For changes under Lib/test, adding frozendict and slice to generic_types changes the test data, while repository policy allows only expected-failure decorator edits. Revert this migrated type-list change rather than modifying the test inputs.
AGENTS.md reference: AGENTS.md:L278-L282
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
f.__annotate__ = lambda x: 42
|
|
|
with self.assertRaisesRegex(TypeError, r"__annotate__ returned non-dict of type 'int'"):
|
|
|
with self.assertRaisesRegex(TypeError, r"__annotate__\(\) must return a dict, not int"):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the annotation test oracle
For changes under Lib/test, this assertRaisesRegex rewrite modifies a test assertion, but repository policy permits only adding or removing expected-failure decorators in test files. Restore the assertion and use an allowed marker if the implementation cannot satisfy it so the implementation change does not move its own oracle.
AGENTS.md reference: AGENTS.md:L278-L282
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|