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

Method finalize_object

crates/stdlib/src/json.rs:472–503  ·  view source on GitHub ↗

Finalize object construction with hooks.

(
            &self,
            pairs: Vec<(PyObjectRef, PyObjectRef)>,
            end_char_idx: usize,
            end_byte_idx: usize,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

470
471 /// Finalize object construction with hooks.
472 fn finalize_object(
473 &self,
474 pairs: Vec<(PyObjectRef, PyObjectRef)>,
475 end_char_idx: usize,
476 end_byte_idx: usize,
477 vm: &VirtualMachine,
478 ) -> PyResult<(PyObjectRef, usize, usize)> {
479 let result = if let Some(ref pairs_hook) = self.object_pairs_hook {
480 // object_pairs_hook takes priority - pass list of tuples
481 let pairs_list: Vec<PyObjectRef> = pairs
482 .into_iter()
483 .map(|(k, v)| vm.new_tuple((k, v)).into())
484 .collect();
485 pairs_hook.call((vm.ctx.new_list(pairs_list),), vm)?
486 } else {
487 // Build a dict from pairs
488 let dict = vm.ctx.new_dict();
489 for (key, value) in pairs {
490 dict.set_item(&*key, value, vm)?;
491 }
492
493 // Apply object_hook if present
494 let dict_obj: PyObjectRef = dict.into();
495 if let Some(ref hook) = self.object_hook {
496 hook.call((dict_obj,), vm)?
497 } else {
498 dict_obj
499 }
500 };
501
502 Ok((result, end_char_idx, end_byte_idx))
503 }
504
505 /// Call scan_once and handle the result.
506 /// Returns (value, end_char_idx, end_byte_idx).

Callers 1

parse_objectMethod · 0.80

Calls 8

collectMethod · 0.80
new_listMethod · 0.80
new_dictMethod · 0.80
mapMethod · 0.45
into_iterMethod · 0.45
new_tupleMethod · 0.45
callMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected