Repository navigation
Use active builtins consistently in descriptor and method reductions - #9057
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (5)
✨ Finishing Touches
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. Comment |
| #[pymethod] | ||
| fn __reduce__(&self, vm: &VirtualMachine) -> PyResult { | ||
| let getattr = vm.builtins.get_attr("getattr", vm)?; | ||
| let getattr = vm.eval_get_builtin(vm.ctx.intern_str("getattr"))?; |
There was a problem hiding this comment.
tell me why this is important. and also this pattern is looking like need to be applied more places. if it does, patch and include here
There was a problem hiding this comment.
This is observable compatibility of the reconstruction recipe. With a custom active builtins mapping, CPython returns that mapping’s exact getattr object from reduce, without calling it; if the entry is absent, reduction raises AttributeError("getattr"). Reading vm.builtins instead returns a different callable and hides that lookup failure. This is not a sandbox-security claim.
You are right about the other sites. Exact CPython 3.14.8 source and bounded reference/native checks identify the same issue in method/member descriptors, bound native methods, Python bound methods, and method wrappers. I am including those fixes here, with stored defining-type handling and name lookup order preserved, and expanding the existing parameterized Python regression. Module-bound functions still return a name. Classmethod/getset descriptors and pickle’s separately cached getattr have different contracts and are not being changed.
There was a problem hiding this comment.
Included in 4944d19: all five remaining reducer sites now use active builtins; method descriptors retain their actual defining type; Python bound methods keep name lookup first. The helper now performs one generic lookup for dictionary subclasses, preserving inherited missing without an extra fallback after overridden getitem. The original wrapper assertions remain covered in the expanded table.
Exact CPython 3.14.7/3.14.8 reference matrices and the native candidate agree, including callback counts and exception order. The full pickle snippet, both snippet pytest entries, four unchanged canonical method/iterator tests, normal hooks, and VM/CAPI Clippy pass. Two pre-existing C-method pickle expected failures remain unchanged. Module-bound functions, classmethod/getset descriptors, and pickle’s cached getattr retain their distinct contracts. New-head CI is running.
4944d19 to
4da26ee
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
4da26ee to
7a320ce
Compare
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] test: cpython/Lib/test/test_mmap.py (TODO: 19) dependencies: dependent tests: (2 tests)
Legend:
|
7a320ce to
d9c81d9
Compare
d9c81d9 to
9be5575
Compare
9be5575 to
9f54393
Compare
Use frame-aware getattr lookup consistently across descriptor and method reductions. Preserve defining types and exception order, and perform generic builtin-mapping subclass lookup only once. Assisted-by: OpenAI Codex:model identifier unavailable
9f54393 to
bf4bbf6
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf4bbf6586
ℹ️ 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".
| assert str(caught.exception) == expected | ||
|
|
||
|
|
||
| # Reduction returns getattr from the active frame's builtins without calling it. |
There was a problem hiding this comment.
Remove prohibited test-logic changes
This added regression block introduces new test data, execution logic, and assertions in a test file, while the repository permits test-file edits only for adding or removing expected-failure decorators; the test additions therefore need to be removed unless the maintainers revise that policy first.
AGENTS.md reference: AGENTS.md:L275-L279
Useful? React with 👍 / 👎.
Current revision
Targets Python 3.15
mainatf39da82d9d38cd5bdceb9e645205e830f65126fbwith one logical commit,bf4bbf65869e47949ffb5abe5d9aeb4798e57098. The unique patch is unchanged from the prior reviewed PR head (range-diff=); current main fixes, original author attribution, and assistance trailers are preserved. No files underLib/are changed.Normal commit hooks, changed-range hooks, whitespace checks, and source-equivalence review passed. Normal hosted CI is enabled for this exact head. Current-revision local validation is source and hooks only; earlier runtime results below remain attributed to their original revisions.
Summary
Follow up on merged #9037 and its original review, expanded after the same-pattern audit request.
Reduction must return the active frame's exact
getattrvalue without calling it, and raiseAttributeError('getattr')when absent. Reading the interpreter-global builtins instead changes both the reconstruction callable and the failure behavior.io.BytesIOthat are not attributes ofbuiltins.__name__before looking upgetattr, preserving exception order.__missing__after its overridden__getitem__raisesKeyError. Existing iterator reducers share this correction.Module-bound native functions still reduce to their names. Classmethod/getset descriptors and pickle's separately cached
getattrhave different contracts and are unchanged.The same behavior is established by CPython 3.14.7 and 3.14.8. Sources: descriptor reducers, native method reducer, Python method order, and optional mapping lookup.
Earlier validation before stacking on #8950
__missing__still works; custom__getitem__is not followed by a second__missing__call. Negative classmethod/getset controls retain their errors.-D warnings.All new behavior assertions are Python tests.