MCPcopy Index your code
hub / github.com/RustPython/RustPython / reduce

Method reduce

crates/vm/src/builtins/iter.rs:76–92  ·  view source on GitHub ↗

Build a pickle-compatible reduce tuple. `func` must be resolved **before** acquiring any lock that guards this `PositionIterInternal`, so that the builtins lookup cannot trigger reentrant iterator access and deadlock.

(
        &self,
        func: PyObjectRef,
        active: F,
        empty: E,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

74 /// `PositionIterInternal`, so that the builtins lookup cannot trigger
75 /// reentrant iterator access and deadlock.
76 pub fn reduce<F, E>(
77 &self,
78 func: PyObjectRef,
79 active: F,
80 empty: E,
81 vm: &VirtualMachine,
82 ) -> PyTupleRef
83 where
84 F: FnOnce(&T) -> PyObjectRef,
85 E: FnOnce(&VirtualMachine) -> PyObjectRef,
86 {
87 if let IterStatus::Active(obj) = &self.status {
88 vm.new_tuple((func, (active(obj),), self.position))
89 } else {
90 vm.new_tuple((func, (empty(vm),)))
91 }
92 }
93
94 fn _next<F, OP>(&mut self, f: F, op: OP) -> PyResult<PyIterReturn>
95 where

Callers 15

_eval_typeFunction · 0.45
_strip_annotationsFunction · 0.45
test_reduceMethod · 0.45
test_iterator_usageMethod · 0.45
test_initial_keywordMethod · 0.45
test_monitoring.pyFile · 0.45
via_reduceFunction · 0.45
last_itemMethod · 0.45
composeFunction · 0.45
loadMethod · 0.45
__reduce__Method · 0.45

Calls 1

new_tupleMethod · 0.45

Tested by 6

test_reduceMethod · 0.36
test_iterator_usageMethod · 0.36
test_initial_keywordMethod · 0.36
via_reduceFunction · 0.36
last_itemMethod · 0.36