From abee1c14e7df05a08d559d9fce7435b9e2aced9e Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 8 Oct 2026 17:20:28 -0700 Subject: [PATCH] refactor(python-bridge): derive NativeCall extraction (#45449) Co-authored-by: Claude Opus 5.5 --- .../crates/python-bridge/src/routes/mod.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/litellm-rust/crates/python-bridge/src/routes/mod.rs b/litellm-rust/crates/python-bridge/src/routes/mod.rs index 646b7799730..deb29f12bab 100644 --- a/litellm-rust/crates/python-bridge/src/routes/mod.rs +++ b/litellm-rust/crates/python-bridge/src/routes/mod.rs @@ -16,24 +16,16 @@ use pyo3::{ types::{PyDict, PyMapping, PyTuple}, }; +#[derive(FromPyObject)] pub(crate) struct NativeCall<'py> { + #[pyo3(attribute)] args: Bound<'py, PyTuple>, + #[pyo3(attribute, from_py_with = mapping_dict)] kwargs: Bound<'py, PyDict>, + #[pyo3(attribute, from_py_with = mapping_dict)] bound: Bound<'py, PyDict>, } -impl<'py> FromPyObject<'_, 'py> for NativeCall<'py> { - type Error = PyErr; - - fn extract(call: Borrowed<'_, 'py, PyAny>) -> PyResult { - Ok(Self { - args: call.getattr("args")?.cast_into()?, - kwargs: mapping_dict(&call.getattr("kwargs")?)?, - bound: mapping_dict(&call.getattr("bound")?)?, - }) - } -} - fn mapping_dict<'py>(value: &Bound<'py, PyAny>) -> PyResult> { if let Ok(dict) = value.cast::() { return Ok(dict.clone());