Skip to content

Commit 75d84b9

Browse files
committed
Fix pyo3 deprecations
1 parent b7a8670 commit 75d84b9

File tree

10 files changed

+19
-25
lines changed

10 files changed

+19
-25
lines changed

nautilus_core/backtest/src/engine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod tests {
115115

116116
use nautilus_common::timer::TimeEvent;
117117
use nautilus_core::uuid::UUID4;
118-
use pyo3::{types::PyList, Py, Python};
118+
use pyo3::{prelude::*, types::PyList, Py, Python};
119119
use rstest::*;
120120
use ustr::Ustr;
121121

@@ -126,7 +126,7 @@ mod tests {
126126
pyo3::prepare_freethreaded_python();
127127

128128
Python::with_gil(|py| {
129-
let py_list = PyList::empty(py);
129+
let py_list = PyList::empty_bound(py);
130130
let py_append = Py::from(py_list.getattr("append").unwrap());
131131

132132
let mut accumulator = TimeEventAccumulator::new();

nautilus_core/backtest/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@
2727
//! - `ffi`: Enables the C foreign function interface (FFI) from `cbindgen`
2828
//! - `python`: Enables Python bindings from `pyo3`
2929
30-
#![allow(deprecated)] // TODO: Temporary for pyo3 upgrade
31-
3230
pub mod engine;
3331
pub mod matching_engine;

nautilus_core/common/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
//! - `python`: Enables Python bindings from `pyo3`
2929
//! - `stubs`: Enables type stubs for use in testing scenarios
3030
31-
#![allow(deprecated)] // TODO: Temporary for pyo3 upgrade
32-
3331
pub mod cache;
3432
pub mod clock;
3533
pub mod enums;

nautilus_core/common/src/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ mod tests {
474474
pyo3::prepare_freethreaded_python();
475475

476476
let handler = Python::with_gil(|py| {
477-
let callable = wrap_pyfunction!(receive_event, py).unwrap();
477+
let callable = wrap_pyfunction_bound!(receive_event, py).unwrap();
478478
EventHandler::new(callable.into_py(py))
479479
});
480480

@@ -500,7 +500,7 @@ mod tests {
500500
pyo3::prepare_freethreaded_python();
501501

502502
let handler = Python::with_gil(|py| {
503-
let callable = wrap_pyfunction!(receive_event, py).unwrap();
503+
let callable = wrap_pyfunction_bound!(receive_event, py).unwrap();
504504
EventHandler::new(callable.into_py(py))
505505
});
506506

@@ -532,7 +532,7 @@ mod tests {
532532
pyo3::prepare_freethreaded_python();
533533

534534
let handler = Python::with_gil(|py| {
535-
let callable = wrap_pyfunction!(receive_event, py).unwrap();
535+
let callable = wrap_pyfunction_bound!(receive_event, py).unwrap();
536536
EventHandler::new(callable.into_py(py))
537537
});
538538

nautilus_core/model/src/data/quote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod tests {
217217

218218
Python::with_gil(|py| {
219219
let tick_pyobject = tick.into_py(py);
220-
let parsed_tick = QuoteTick::from_pyobject(tick_pyobject.as_ref(py)).unwrap();
220+
let parsed_tick = QuoteTick::from_pyobject(tick_pyobject.bind(py)).unwrap();
221221
assert_eq!(parsed_tick, tick);
222222
});
223223
}

nautilus_core/model/src/data/trade.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ mod tests {
181181

182182
Python::with_gil(|py| {
183183
let tick_pyobject = trade.into_py(py);
184-
let parsed_tick = TradeTick::from_pyobject(tick_pyobject.as_ref(py)).unwrap();
184+
let parsed_tick = TradeTick::from_pyobject(tick_pyobject.bind(py)).unwrap();
185185
assert_eq!(parsed_tick, trade);
186186
});
187187
}

nautilus_core/model/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
//! - `python`: Enables Python bindings from `pyo3`
2929
//! - `stubs`: Enables type stubs for use in testing scenarios
3030
31-
#![allow(deprecated)] // TODO: Temporary for pyo3 upgrade
32-
3331
pub mod currencies;
3432
pub mod data;
3533
pub mod enums;

nautilus_core/model/src/python/data/quote.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ use crate::{
4141

4242
impl QuoteTick {
4343
/// Create a new [`QuoteTick`] extracted from the given [`PyAny`].
44-
pub fn from_pyobject(obj: &PyAny) -> PyResult<Self> {
44+
pub fn from_pyobject(obj: &Bound<PyAny>) -> PyResult<Self> {
4545
let instrument_id_obj: &PyAny = obj.getattr("instrument_id")?.extract()?;
4646
let instrument_id_str = instrument_id_obj.getattr("value")?.extract()?;
4747
let instrument_id = InstrumentId::from_str(instrument_id_str).map_err(to_pyvalue_err)?;
4848

49-
let bid_price_py: &PyAny = obj.getattr("bid_price")?;
49+
let bid_price_py: &PyAny = obj.getattr("bid_price")?.extract()?;
5050
let bid_price_raw: i64 = bid_price_py.getattr("raw")?.extract()?;
5151
let bid_price_prec: u8 = bid_price_py.getattr("precision")?.extract()?;
5252
let bid_price = Price::from_raw(bid_price_raw, bid_price_prec).map_err(to_pyvalue_err)?;
5353

54-
let ask_price_py: &PyAny = obj.getattr("ask_price")?;
54+
let ask_price_py: &PyAny = obj.getattr("ask_price")?.extract()?;
5555
let ask_price_raw: i64 = ask_price_py.getattr("raw")?.extract()?;
5656
let ask_price_prec: u8 = ask_price_py.getattr("precision")?.extract()?;
5757
let ask_price = Price::from_raw(ask_price_raw, ask_price_prec).map_err(to_pyvalue_err)?;
5858

59-
let bid_size_py: &PyAny = obj.getattr("bid_size")?;
59+
let bid_size_py: &PyAny = obj.getattr("bid_size")?.extract()?;
6060
let bid_size_raw: u64 = bid_size_py.getattr("raw")?.extract()?;
6161
let bid_size_prec: u8 = bid_size_py.getattr("precision")?.extract()?;
6262
let bid_size = Quantity::from_raw(bid_size_raw, bid_size_prec).map_err(to_pyvalue_err)?;
6363

64-
let ask_size_py: &PyAny = obj.getattr("ask_size")?;
64+
let ask_size_py: &PyAny = obj.getattr("ask_size")?.extract()?;
6565
let ask_size_raw: u64 = ask_size_py.getattr("raw")?.extract()?;
6666
let ask_size_prec: u8 = ask_size_py.getattr("precision")?.extract()?;
6767
let ask_size = Quantity::from_raw(ask_size_raw, ask_size_prec).map_err(to_pyvalue_err)?;
@@ -423,7 +423,7 @@ mod tests {
423423

424424
Python::with_gil(|py| {
425425
let tick_pyobject = tick.into_py(py);
426-
let parsed_tick = QuoteTick::from_pyobject(tick_pyobject.as_ref(py)).unwrap();
426+
let parsed_tick = QuoteTick::from_pyobject(tick_pyobject.bind(py)).unwrap();
427427
assert_eq!(parsed_tick, tick);
428428
});
429429
}

nautilus_core/model/src/python/data/trade.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ use crate::{
4141

4242
impl TradeTick {
4343
/// Create a new [`TradeTick`] extracted from the given [`PyAny`].
44-
pub fn from_pyobject(obj: &PyAny) -> PyResult<Self> {
44+
pub fn from_pyobject(obj: &Bound<PyAny>) -> PyResult<Self> {
4545
let instrument_id_obj: &PyAny = obj.getattr("instrument_id")?.extract()?;
4646
let instrument_id_str = instrument_id_obj.getattr("value")?.extract()?;
4747
let instrument_id = InstrumentId::from_str(instrument_id_str).map_err(to_pyvalue_err)?;
4848

49-
let price_py: &PyAny = obj.getattr("price")?;
49+
let price_py: &PyAny = obj.getattr("price")?.extract()?;
5050
let price_raw: i64 = price_py.getattr("raw")?.extract()?;
5151
let price_prec: u8 = price_py.getattr("precision")?.extract()?;
5252
let price = Price::from_raw(price_raw, price_prec).map_err(to_pyvalue_err)?;
5353

54-
let size_py: &PyAny = obj.getattr("size")?;
54+
let size_py: &PyAny = obj.getattr("size")?.extract()?;
5555
let size_raw: u64 = size_py.getattr("raw")?.extract()?;
5656
let size_prec: u8 = size_py.getattr("precision")?.extract()?;
5757
let size = Quantity::from_raw(size_raw, size_prec).map_err(to_pyvalue_err)?;
@@ -372,7 +372,7 @@ mod tests {
372372

373373
Python::with_gil(|py| {
374374
let tick_pyobject = tick.into_py(py);
375-
let parsed_tick = TradeTick::from_pyobject(tick_pyobject.as_ref(py)).unwrap();
375+
let parsed_tick = TradeTick::from_pyobject(tick_pyobject.bind(py)).unwrap();
376376
assert_eq!(parsed_tick, tick);
377377
});
378378
}

nautilus_core/persistence/src/python/backend/transformer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl DataTransformer {
6060
fn pyobjects_to_quote_ticks(py: Python<'_>, data: Vec<PyObject>) -> PyResult<Vec<QuoteTick>> {
6161
let ticks: Vec<QuoteTick> = data
6262
.into_iter()
63-
.map(|obj| QuoteTick::from_pyobject(obj.as_ref(py)))
63+
.map(|obj| QuoteTick::from_pyobject(obj.bind(py)))
6464
.collect::<PyResult<Vec<QuoteTick>>>()?;
6565

6666
// Validate monotonically increasing
@@ -75,7 +75,7 @@ impl DataTransformer {
7575
fn pyobjects_to_trade_ticks(py: Python<'_>, data: Vec<PyObject>) -> PyResult<Vec<TradeTick>> {
7676
let ticks: Vec<TradeTick> = data
7777
.into_iter()
78-
.map(|obj| TradeTick::from_pyobject(obj.as_ref(py)))
78+
.map(|obj| TradeTick::from_pyobject(obj.bind(py)))
7979
.collect::<PyResult<Vec<TradeTick>>>()?;
8080

8181
// Validate monotonically increasing

0 commit comments

Comments
 (0)