Skip to content

Commit

Permalink
fix rust warning in python binding (#5459)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Dec 26, 2024
1 parent 22d2cef commit 4aa0e57
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
31 changes: 20 additions & 11 deletions bindings/python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl File {
impl File {
/// Read and return at most size bytes, or if size is not given, until EOF.
#[pyo3(signature = (size=None,))]
pub fn read<'p>(&'p mut self, py: Python<'p>, size: Option<usize>) -> PyResult<Bound<PyAny>> {
pub fn read<'p>(
&'p mut self,
py: Python<'p>,
size: Option<usize>,
) -> PyResult<Bound<'p, PyAny>> {
let reader = match &mut self.0 {
FileState::Reader(r) => r,
FileState::Writer(_) => {
Expand Down Expand Up @@ -107,7 +111,7 @@ impl File {
&'p mut self,
py: Python<'p>,
size: Option<usize>,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let reader = match &mut self.0 {
FileState::Reader(r) => r,
FileState::Writer(_) => {
Expand Down Expand Up @@ -352,7 +356,7 @@ impl AsyncFile {
impl AsyncFile {
/// Read and return at most size bytes, or if size is not given, until EOF.
#[pyo3(signature = (size=None))]
pub fn read<'p>(&'p self, py: Python<'p>, size: Option<usize>) -> PyResult<Bound<PyAny>> {
pub fn read<'p>(&'p self, py: Python<'p>, size: Option<usize>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();

future_into_py(py, async move {
Expand Down Expand Up @@ -397,7 +401,7 @@ impl AsyncFile {
}

/// Write bytes into the file.
pub fn write<'p>(&'p mut self, py: Python<'p>, bs: &'p [u8]) -> PyResult<Bound<PyAny>> {
pub fn write<'p>(&'p mut self, py: Python<'p>, bs: &'p [u8]) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();

// FIXME: can we avoid this clone?
Expand Down Expand Up @@ -438,7 +442,12 @@ impl AsyncFile {
///
/// Return the new absolute position.
#[pyo3(signature = (pos, whence = 0))]
pub fn seek<'p>(&'p mut self, py: Python<'p>, pos: i64, whence: u8) -> PyResult<Bound<PyAny>> {
pub fn seek<'p>(
&'p mut self,
py: Python<'p>,
pos: i64,
whence: u8,
) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();

let whence = match whence {
Expand Down Expand Up @@ -474,7 +483,7 @@ impl AsyncFile {
}

/// Return the current stream position.
pub fn tell<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
pub fn tell<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();

future_into_py(py, async move {
Expand Down Expand Up @@ -502,7 +511,7 @@ impl AsyncFile {
.and_then(|pos| pos.into_bound_py_any(py))
}

fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();
future_into_py(py, async move {
let mut state = state.lock().await;
Expand Down Expand Up @@ -532,7 +541,7 @@ impl AsyncFile {
}

/// Check if the stream may be read from.
pub fn readable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
pub fn readable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();
future_into_py(py, async move {
let state = state.lock().await;
Expand All @@ -541,7 +550,7 @@ impl AsyncFile {
}

/// Check if the stream may be written to.
pub fn writable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
pub fn writable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();
future_into_py(py, async move {
let state = state.lock().await;
Expand All @@ -550,7 +559,7 @@ impl AsyncFile {
}

/// Check if the stream reader may be re-located.
pub fn seekable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
pub fn seekable<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
if true {
self.readable(py)
} else {
Expand All @@ -560,7 +569,7 @@ impl AsyncFile {

/// Check if the stream is closed.
#[getter]
pub fn closed<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
pub fn closed<'p>(&'p self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
let state = self.0.clone();
future_into_py(py, async move {
let state = state.lock().await;
Expand Down
30 changes: 15 additions & 15 deletions bindings/python/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Operator {
}

/// Read the whole path into bytes.
pub fn read<'p>(&'p self, py: Python<'p>, path: &str) -> PyResult<Bound<PyAny>> {
pub fn read<'p>(&'p self, py: Python<'p>, path: &str) -> PyResult<Bound<'p, PyAny>> {
let buffer = self.core.read(path).map_err(format_pyerr)?.to_vec();
Buffer::new(buffer).into_bytes_ref(py)
}
Expand Down Expand Up @@ -287,7 +287,7 @@ impl AsyncOperator {
py: Python<'p>,
path: String,
mode: String,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();

future_into_py(py, async move {
Expand All @@ -312,7 +312,7 @@ impl AsyncOperator {
}

/// Read the whole path into bytes.
pub fn read<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn read<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let res: Vec<u8> = this.read(&path).await.map_err(format_pyerr)?.to_vec();
Expand All @@ -328,7 +328,7 @@ impl AsyncOperator {
path: String,
bs: &Bound<PyBytes>,
kwargs: Option<WriteOptions>,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let kwargs = kwargs.unwrap_or_default();
let this = self.core.clone();
let bs = bs.as_bytes().to_vec();
Expand All @@ -351,7 +351,7 @@ impl AsyncOperator {
}

/// Get current path's metadata **without cache** directly.
pub fn stat<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn stat<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let res: Metadata = this
Expand All @@ -370,7 +370,7 @@ impl AsyncOperator {
py: Python<'p>,
source: String,
target: String,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
this.copy(&source, &target).await.map_err(format_pyerr)
Expand All @@ -383,15 +383,15 @@ impl AsyncOperator {
py: Python<'p>,
source: String,
target: String,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
this.rename(&source, &target).await.map_err(format_pyerr)
})
}

/// Remove all file
pub fn remove_all<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn remove_all<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
this.remove_all(&path).await.map_err(format_pyerr)
Expand All @@ -410,7 +410,7 @@ impl AsyncOperator {
///
/// - Create on existing dir will succeed.
/// - Create dir is always recursive, works like `mkdir -p`
pub fn create_dir<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn create_dir<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
this.create_dir(&path).await.map_err(format_pyerr)
Expand All @@ -422,7 +422,7 @@ impl AsyncOperator {
/// # Notes
///
/// - Delete not existing error won't return errors.
pub fn delete<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn delete<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(
py,
Expand All @@ -431,7 +431,7 @@ impl AsyncOperator {
}

/// List current dir path.
pub fn list<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn list<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let lister = this.lister(&path).await.map_err(format_pyerr)?;
Expand All @@ -442,7 +442,7 @@ impl AsyncOperator {
}

/// List dir in flat way.
pub fn scan<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<PyAny>> {
pub fn scan<'p>(&'p self, py: Python<'p>, path: String) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let lister = this
Expand All @@ -462,7 +462,7 @@ impl AsyncOperator {
py: Python<'p>,
path: String,
expire_second: u64,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let res = this
Expand All @@ -481,7 +481,7 @@ impl AsyncOperator {
py: Python<'p>,
path: String,
expire_second: u64,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let res = this
Expand All @@ -500,7 +500,7 @@ impl AsyncOperator {
py: Python<'p>,
path: String,
expire_second: u64,
) -> PyResult<Bound<PyAny>> {
) -> PyResult<Bound<'p, PyAny>> {
let this = self.core.clone();
future_into_py(py, async move {
let res = this
Expand Down

0 comments on commit 4aa0e57

Please sign in to comment.