Skip to content

Commit 85de72d

Browse files
authored
chore: bump pyo3 to 0.21 (#175)
Roughly adapt the code to the new PyO3 API, with a few warning fixes.
1 parent 1516153 commit 85de72d

File tree

8 files changed

+81
-136
lines changed

8 files changed

+81
-136
lines changed

Cargo.lock

Lines changed: 44 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ default = ["zenoh/default"]
4141
maintenance = { status = "actively-developed" }
4242

4343
[dependencies]
44-
env_logger = "0.10.0"
44+
env_logger = "0.11.3"
4545
flume = "0.11.0"
4646
json5 = "0.4.1"
47-
pyo3 = { version = "0.18.1", features = ["extension-module", "abi3-py37"] }
47+
pyo3 = { version = "0.21.1", features = ["extension-module", "abi3-py37"] }
4848
uhlc = "0.6.0"
4949
validated_struct = "2.1.0"
5050
zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["unstable"], default-features = false }

src/closures.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ trait CallbackUnwrap {
2929
impl<T> CallbackUnwrap for PyResult<T> {
3030
type Output = T;
3131
fn cb_unwrap(self) -> Self::Output {
32-
match self {
33-
Ok(o) => o,
34-
Err(e) => Python::with_gil(|py| {
35-
if let Some(trace) = e.traceback(py).and_then(|trace| trace.format().ok()) {
32+
self.unwrap_or_else(|e| {
33+
Python::with_gil(|py| {
34+
if let Some(trace) = e.traceback_bound(py).and_then(|trace| trace.format().ok()) {
3635
panic!("Exception thrown in callback: {}.\n{}", e, trace)
3736
} else {
3837
panic!("Exception thrown in callback: {}.", e,)
3938
}
40-
}),
41-
}
39+
})
40+
})
4241
}
4342
}
4443

@@ -47,9 +46,9 @@ pub(crate) struct PyClosure<I> {
4746
pub(crate) drop: Option<Py<PyAny>>,
4847
_marker: std::marker::PhantomData<I>,
4948
}
50-
impl<I> TryFrom<&PyAny> for PyClosure<I> {
49+
impl<I> TryFrom<&Bound<'_, PyAny>> for PyClosure<I> {
5150
type Error = PyErr;
52-
fn try_from(value: &PyAny) -> Result<Self, Self::Error> {
51+
fn try_from(value: &Bound<PyAny>) -> Result<Self, Self::Error> {
5352
Python::with_gil(|py| {
5453
let pycall = match value.getattr("call") {
5554
Ok(value) => value.into_py(py),
@@ -169,15 +168,15 @@ impl _Queue {
169168
Err(flume::RecvTimeoutError::Disconnected) => break,
170169
Err(flume::RecvTimeoutError::Timeout) => {
171170
let list: Py<PyList> =
172-
Python::with_gil(|py| PyList::new(py, vec).into_py(py));
171+
Python::with_gil(|py| PyList::new_bound(py, vec).into());
173172
return Err(pyo3::exceptions::PyTimeoutError::new_err((list,)));
174173
}
175174
}
176175
}
177176
vec
178177
}
179178
};
180-
Ok(Python::with_gil(|py| PyList::new(py, vec).into_py(py)))
179+
Ok(Python::with_gil(|py| PyList::new_bound(py, vec).into()))
181180
})
182181
}
183182
pub fn is_closed(&self) -> bool {

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl _Config {
6363
pub fn from_json5(expr: &str) -> PyResult<Self> {
6464
match Config::from_deserializer(&mut json5::Deserializer::from_str(expr).to_pyres()?) {
6565
Ok(k) => Ok(Self(PyConfig::Config(Box::new(k)))),
66-
Err(Ok(_)) => Err(zenoh_core::zerror!(
66+
Err(Ok(_)) => Err(zerror!(
6767
"{} did parse into a config, but invalid values were found",
6868
expr,
6969
)

src/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl _Priority {
147147
}
148148
}
149149
}
150-
impl std::cmp::PartialOrd for _Priority {
150+
impl PartialOrd for _Priority {
151151
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
152152
(self.0 as u8).partial_cmp(&(other.0 as u8))
153153
}

0 commit comments

Comments
 (0)