Skip to content

Commit 5945834

Browse files
authored
Merge pull request #115 from influxdata/crepererum/err-wrapper-no-dict
fix: `Err` should not be a `dict` in Python
2 parents 1fa98a5 + c464190 commit 5945834

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
@@ -1567,7 +1567,7 @@ mod wit_world {
15671567
}
15681568

15691569
#[pyclass]
1570-
#[derive(Debug, IntoPyObject)]
1570+
#[derive(Debug)]
15711571
#[pyo3(extends = PyValueError, frozen, get_all, name = "Err", str)]
15721572
pub(crate) struct ErrWrapper {
15731573
value: Py<PyAny>,
@@ -1628,9 +1628,9 @@ mod wit_world {
16281628
#[derive(Debug, IntoPyObject)]
16291629
pub(crate) enum ResultWrapper {
16301630
#[pyo3(transparent)]
1631-
Ok(OkWrapper),
1631+
Ok(Py<OkWrapper>),
16321632
#[pyo3(transparent)]
1633-
Err(ErrWrapper),
1633+
Err(Py<ErrWrapper>),
16341634
}
16351635

16361636
impl ResultWrapper {
@@ -1640,26 +1640,30 @@ mod wit_world {
16401640
E: IntoPyObject<'py>,
16411641
{
16421642
let res = match res {
1643-
Ok(val) => Self::Ok(OkWrapper {
1644-
value: val
1643+
Ok(val) => {
1644+
let val = val
16451645
.into_pyobject(py)
16461646
.map_err(|e| {
16471647
let e: PyErr = e.into();
16481648
e
16491649
})?
16501650
.into_any()
1651-
.unbind(),
1652-
}),
1653-
Err(val) => Self::Err(ErrWrapper {
1654-
value: val
1651+
.unbind();
1652+
1653+
Self::Ok(Py::new(py, OkWrapper { value: val })?)
1654+
}
1655+
Err(val) => {
1656+
let val = val
16551657
.into_pyobject(py)
16561658
.map_err(|e| {
16571659
let e: PyErr = e.into();
16581660
e
16591661
})?
16601662
.into_any()
1661-
.unbind(),
1662-
}),
1663+
.unbind();
1664+
1665+
Self::Err(Py::new(py, ErrWrapper { value: val })?)
1666+
}
16631667
};
16641668
Ok(res)
16651669
}

0 commit comments

Comments
 (0)