Skip to content

Commit b81df16

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 ceee578 commit b81df16

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
@@ -1436,7 +1436,7 @@ mod wit_world {
14361436
}
14371437

14381438
#[pyclass]
1439-
#[derive(Debug, IntoPyObject)]
1439+
#[derive(Debug)]
14401440
#[pyo3(extends = PyValueError, frozen, get_all, name = "Err")]
14411441
pub(crate) struct ErrWrapper {
14421442
value: Py<PyAny>,
@@ -1487,9 +1487,9 @@ mod wit_world {
14871487
#[derive(Debug, IntoPyObject)]
14881488
pub(crate) enum ResultWrapper {
14891489
#[pyo3(transparent)]
1490-
Ok(OkWrapper),
1490+
Ok(Py<OkWrapper>),
14911491
#[pyo3(transparent)]
1492-
Err(ErrWrapper),
1492+
Err(Py<ErrWrapper>),
14931493
}
14941494

14951495
impl ResultWrapper {
@@ -1499,26 +1499,30 @@ mod wit_world {
14991499
E: IntoPyObject<'py>,
15001500
{
15011501
let res = match res {
1502-
Ok(val) => Self::Ok(OkWrapper {
1503-
value: val
1502+
Ok(val) => {
1503+
let val = val
15041504
.into_pyobject(py)
15051505
.map_err(|e| {
15061506
let e: PyErr = e.into();
15071507
e
15081508
})?
15091509
.into_any()
1510-
.unbind(),
1511-
}),
1512-
Err(val) => Self::Err(ErrWrapper {
1513-
value: val
1510+
.unbind();
1511+
1512+
Self::Ok(Py::new(py, OkWrapper { value: val })?)
1513+
}
1514+
Err(val) => {
1515+
let val = val
15141516
.into_pyobject(py)
15151517
.map_err(|e| {
15161518
let e: PyErr = e.into();
15171519
e
15181520
})?
15191521
.into_any()
1520-
.unbind(),
1521-
}),
1522+
.unbind();
1523+
1524+
Self::Err(Py::new(py, ErrWrapper { value: val })?)
1525+
}
15221526
};
15231527
Ok(res)
15241528
}

0 commit comments

Comments
 (0)