Skip to content

Commit c464190

Browse files
committed
fix: Err should not be a dict in Python
Turns out `#[derive(IntoPyObject)]` for structs just creates a `dict`, which is not what we want.
1 parent 234cb4d commit c464190

File tree

1 file changed

+15
-11
lines changed
  • guests/python/src/python_modules

1 file changed

+15
-11
lines changed

guests/python/src/python_modules/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ mod wit_world {
15641564
}
15651565

15661566
#[pyclass]
1567-
#[derive(Debug, IntoPyObject)]
1567+
#[derive(Debug)]
15681568
#[pyo3(extends = PyValueError, frozen, get_all, name = "Err", str)]
15691569
pub(crate) struct ErrWrapper {
15701570
value: Py<PyAny>,
@@ -1623,9 +1623,9 @@ mod wit_world {
16231623
#[derive(Debug, IntoPyObject)]
16241624
pub(crate) enum ResultWrapper {
16251625
#[pyo3(transparent)]
1626-
Ok(OkWrapper),
1626+
Ok(Py<OkWrapper>),
16271627
#[pyo3(transparent)]
1628-
Err(ErrWrapper),
1628+
Err(Py<ErrWrapper>),
16291629
}
16301630

16311631
impl ResultWrapper {
@@ -1635,26 +1635,30 @@ mod wit_world {
16351635
E: IntoPyObject<'py>,
16361636
{
16371637
let res = match res {
1638-
Ok(val) => Self::Ok(OkWrapper {
1639-
value: val
1638+
Ok(val) => {
1639+
let val = val
16401640
.into_pyobject(py)
16411641
.map_err(|e| {
16421642
let e: PyErr = e.into();
16431643
e
16441644
})?
16451645
.into_any()
1646-
.unbind(),
1647-
}),
1648-
Err(val) => Self::Err(ErrWrapper {
1649-
value: val
1646+
.unbind();
1647+
1648+
Self::Ok(Py::new(py, OkWrapper { value: val })?)
1649+
}
1650+
Err(val) => {
1651+
let val = val
16501652
.into_pyobject(py)
16511653
.map_err(|e| {
16521654
let e: PyErr = e.into();
16531655
e
16541656
})?
16551657
.into_any()
1656-
.unbind(),
1657-
}),
1658+
.unbind();
1659+
1660+
Self::Err(Py::new(py, ErrWrapper { value: val })?)
1661+
}
16581662
};
16591663
Ok(res)
16601664
}

0 commit comments

Comments
 (0)