MCPcopy Create free account
hub / github.com/RustPython/RustPython / adapt

Function adapt

crates/stdlib/src/_sqlite3.rs:775–805  ·  view source on GitHub ↗
(
        obj: PyObjectRef,
        proto: OptionalArg<Option<PyTypeRef>>,
        alt: OptionalArg<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

773
774 #[pyfunction]
775 fn adapt(
776 obj: PyObjectRef,
777 proto: OptionalArg<Option<PyTypeRef>>,
778 alt: OptionalArg<PyObjectRef>,
779 vm: &VirtualMachine,
780 ) -> PyResult {
781 if matches!(proto, OptionalArg::Present(None)) {
782 return if let OptionalArg::Present(alt) = alt {
783 Ok(alt)
784 } else {
785 Err(new_programming_error(vm, "can't adapt".to_owned()))
786 };
787 }
788
789 let proto = proto
790 .flatten()
791 .unwrap_or_else(|| PrepareProtocol::class(&vm.ctx).to_owned());
792
793 _adapt(
794 &obj,
795 proto,
796 |_| {
797 if let OptionalArg::Present(alt) = alt {
798 Ok(alt)
799 } else {
800 Err(new_programming_error(vm, "can't adapt".to_owned()))
801 }
802 },
803 vm,
804 )
805 }
806
807 fn need_adapt(obj: &PyObject, vm: &VirtualMachine) -> bool {
808 if BASE_TYPE_ADAPTED.get().is_some() {

Callers

nothing calls this directly

Calls 4

_adaptFunction · 0.85
ErrClass · 0.50
to_ownedMethod · 0.45
flattenMethod · 0.45

Tested by

no test coverage detected