refactor(python-bridge): derive NativeCall extraction (#45449)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yujonglee 2026-10-08 17:20:28 -07:00 • committed by GitHub
parent f45407b4c3
commit abee1c14e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<Self> {
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<Bound<'py, PyDict>> {
if let Ok(dict) = value.cast::<PyDict>() {
return Ok(dict.clone());