Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/vm/src/builtins/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,16 @@ impl Callable for PyWrapper {
flags(DISALLOW_INSTANTIATION)
)]
impl Py<PyWrapper> {
#[pymethod]
fn __reduce__(&self, vm: &VirtualMachine) -> PyResult {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required AI-assistance trailer

This commit explicitly states that its implementation and review were AI-assisted, but its message has no Assisted-by: AGENT_NAME:MODEL_VERSION trailer; the repository requires that exact trailer format for every AI-assisted contribution, so rewrite the commit message before merging.

AGENTS.md reference: AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

let getattr = vm.builtins.get_attr("getattr", vm)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve getattr from the current frame's builtins

When __reduce__ is called from an exec/eval frame whose custom __builtins__ mapping overrides or omits getattr, CPython uses that frame-local value (or raises AttributeError), whereas this lookup always reads the interpreter's global builtins module. VirtualMachine::eval_get_builtin already implements the required _PyEval_GetBuiltin semantics, so using the module directly here returns or serializes the wrong callable in custom-builtins contexts.

Useful? React with 👍 / 👎.

let args = vm.ctx.new_tuple(vec![
self.typ.to_owned().into(),
self.name.to_owned().into(),
]);
Ok(vm.ctx.new_tuple(vec![getattr, args.into()]).into())
}

#[pygetset]
fn __qualname__(&self) -> String {
format!("{}.{}", self.typ.name(), self.name)
Expand Down
4 changes: 4 additions & 0 deletions extra_tests/snippets/stdlib_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
assert list(memo) == [1, 7]
assert memo[1] is left
assert memo[7] is left

# Slot wrapper descriptors reduce to lookup on their defining class.
assert object.__str__.__reduce__() == (getattr, (object, "__str__"))
assert _pickle.loads(_pickle.dumps(object.__str__)) is object.__str__
Comment on lines +14 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the forbidden test assertions

These lines add new assertion logic to a test file, but the repository rules prohibit test assertion/logic edits and state that the only acceptable test-file changes are adding or removing expected-failure markers; remove these assertions or obtain an explicit policy exception before merging.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

Loading