Skip to content

Commit 3b2a034

Browse files
committed
fix lint errors
1 parent fe57d9a commit 3b2a034

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

python/src/decoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use bytes::Bytes;
88
use pyo3::exceptions::PyTypeError;
99
use pyo3::intern;
1010
use pyo3::prelude::*;
11-
use pyo3::sync::GILOnceCell;
11+
use pyo3::sync::PyOnceLock;
1212
use pyo3::types::{PyDict, PyTuple};
1313
use pyo3_bytes::PyBytes;
1414

1515
use crate::enums::PyCompressionMethod;
1616

17-
static DEFAULT_DECODER_REGISTRY: GILOnceCell<Arc<DecoderRegistry>> = GILOnceCell::new();
17+
static DEFAULT_DECODER_REGISTRY: PyOnceLock<Arc<DecoderRegistry>> = PyOnceLock::new();
1818

1919
pub fn get_default_decoder_registry(py: Python<'_>) -> Arc<DecoderRegistry> {
2020
let registry =
@@ -49,7 +49,7 @@ impl PyDecoderRegistry {
4949
}
5050

5151
#[derive(Debug)]
52-
pub(crate) struct PyDecoder(PyObject);
52+
pub(crate) struct PyDecoder(Py<PyAny>);
5353

5454
impl PyDecoder {
5555
fn call(&self, py: Python, buffer: Bytes) -> PyResult<PyBytes> {
@@ -78,7 +78,7 @@ impl Decoder for PyDecoder {
7878
_photometric_interpretation: PhotometricInterpretation,
7979
_jpeg_tables: Option<&[u8]>,
8080
) -> AsyncTiffResult<Bytes> {
81-
let decoded_buffer = Python::with_gil(|py| self.call(py, buffer))
81+
let decoded_buffer = Python::attach(|py| self.call(py, buffer))
8282
.map_err(|err| AsyncTiffError::General(err.to_string()))?;
8383
Ok(decoded_buffer.into_inner())
8484
}

python/src/reader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ impl StoreInput {
3636
/// https://developmentseed.org/obspec/latest/api/get/#obspec.GetRangeAsync
3737
/// https://developmentseed.org/obspec/latest/api/get/#obspec.GetRangesAsync
3838
#[derive(Debug)]
39-
pub(crate) struct ObspecBackend(PyObject);
39+
pub(crate) struct ObspecBackend(Py<PyAny>);
4040

4141
impl ObspecBackend {
4242
async fn get_range(&self, path: &str, range: Range<u64>) -> PyResult<PyBytes> {
43-
let future = Python::with_gil(|py| {
43+
let future = Python::attach(|py| {
4444
let kwargs = PyDict::new(py);
4545
kwargs.set_item(intern!(py, "path"), path)?;
4646
kwargs.set_item(intern!(py, "start"), range.start)?;
@@ -52,14 +52,14 @@ impl ObspecBackend {
5252
into_future(coroutine.bind(py).clone())
5353
})?;
5454
let result = future.await?;
55-
Python::with_gil(|py| result.extract(py))
55+
Python::attach(|py| result.extract(py))
5656
}
5757

5858
async fn get_ranges(&self, path: &str, ranges: &[Range<u64>]) -> PyResult<Vec<PyBytes>> {
5959
let starts = ranges.iter().map(|r| r.start).collect::<Vec<_>>();
6060
let ends = ranges.iter().map(|r| r.end).collect::<Vec<_>>();
6161

62-
let future = Python::with_gil(|py| {
62+
let future = Python::attach(|py| {
6363
let kwargs = PyDict::new(py);
6464
kwargs.set_item(intern!(py, "path"), path)?;
6565
kwargs.set_item(intern!(py, "starts"), starts)?;
@@ -71,7 +71,7 @@ impl ObspecBackend {
7171
into_future(coroutine.bind(py).clone())
7272
})?;
7373
let result = future.await?;
74-
Python::with_gil(|py| result.extract(py))
74+
Python::attach(|py| result.extract(py))
7575
}
7676

7777
async fn get_range_wrapper(&self, path: &str, range: Range<u64>) -> AsyncTiffResult<Bytes> {

python/src/thread_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::sync::Arc;
33
use pyo3::exceptions::PyValueError;
44
use pyo3::prelude::*;
55

6-
use pyo3::sync::GILOnceCell;
6+
use pyo3::sync::PyOnceLock;
77
use rayon::{ThreadPool, ThreadPoolBuilder};
88

9-
static DEFAULT_POOL: GILOnceCell<Arc<ThreadPool>> = GILOnceCell::new();
9+
static DEFAULT_POOL: PyOnceLock<Arc<ThreadPool>> = PyOnceLock::new();
1010

1111
pub fn get_default_pool(py: Python<'_>) -> PyResult<Arc<ThreadPool>> {
1212
let runtime = DEFAULT_POOL.get_or_try_init(py, || {

python/src/tile.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ impl PyTile {
5555
}
5656

5757
#[pyo3(signature = (*, decoder_registry=None, pool=None))]
58-
fn decode_async(
58+
fn decode_async<'py>(
5959
&mut self,
60-
py: Python,
60+
py: Python<'py>,
6161
decoder_registry: Option<&PyDecoderRegistry>,
6262
pool: Option<&PyThreadPool>,
63-
) -> PyResult<PyObject> {
63+
) -> PyResult<Bound<'py, PyAny>> {
6464
let decoder_registry = decoder_registry
6565
.map(|r| r.inner().clone())
6666
.unwrap_or_else(|| get_default_decoder_registry(py));
@@ -69,13 +69,12 @@ impl PyTile {
6969
.unwrap_or_else(|| get_default_pool(py))?;
7070
let tile = self.0.take().unwrap();
7171

72-
let result = future_into_py(py, async move {
72+
future_into_py(py, async move {
7373
let decoded_bytes = pool
7474
.spawn_async(move || tile.decode(&decoder_registry))
7575
.await
7676
.unwrap();
7777
Ok(PyBytes::new(decoded_bytes))
78-
})?;
79-
Ok(result.unbind())
78+
})
8079
}
8180
}

0 commit comments

Comments
 (0)