let python_obj = Python::attach(|py| self.inner.clone_ref(py));
let cached_name = self.cached_name.clone();

{{ param_cloning }}

tokio::task::spawn_blocking(move || {
    Python::attach(|py| {
        let obj = python_obj.bind(py);

        {{ py_call }}
        let py_result = {{ call }}
            .map_err(|e| {{ error_expr }})?;
        let json_val: String = py
            .import("json")
            .and_then(|m| m.call_method1("dumps", (py_result,)))
            .and_then(|v| v.extract())
            .map_err(|e| {{ json_error_expr }})?;
        serde_json::from_str::<{{ return_type }}>(&json_val).map_err(|e| {{ deserialize_error_expr }})
    })
})
.await
.map_err(|e| {{ spawn_error_expr }})
.flatten()
