mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Support pickling slot wrapper descriptors (#9037)
Extract wrapper descriptor reduction from #8954 for Python 3.14. Reduce to getattr on the defining class and cover direct reduction plus one roundtrip in the existing pickle snippet. Preserve canonical expected failures for unrelated staticmethod descriptor behavior. Assisted-by: OpenAI Codex:model identifier unavailable
This commit is contained in:
1 parent
b725188965
commit
e3374c8a24
2 files changed
+14
No files matched your search
@@ -2062,6 +2062,16 @@ impl Callable for PyWrapper {
|
||||
flags(DISALLOW_INSTANTIATION)
|
||||
)]
|
||||
impl Py<PyWrapper> {
|
||||
#[pymethod]
|
||||
fn __reduce__(&self, vm: &VirtualMachine) -> PyResult {
|
||||
let getattr = vm.builtins.get_attr("getattr", vm)?;
|
||||
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)
|
||||
|
||||
@@ -9,3 +9,7 @@ memo = unpickler.memo.copy()
|
||||
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__
|
||||
Reference in new issue
Block a user