Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ version = "2.0.10+zstd.1.5.6"
features = ["experimental", "legacy", "zstdmt"]

[dependencies.pyo3]
version = "0.24.2"
version = "0.25.1"
features = ["extension-module"]
6 changes: 3 additions & 3 deletions rust-ext/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
exceptions::{PyIndexError, PyTypeError, PyValueError},
ffi::Py_buffer,
prelude::*,
types::{PyBytes, PyTuple},
types::{PyBytes, PyTuple}, IntoPyObjectExt,
},
};

Expand Down Expand Up @@ -242,7 +242,7 @@ impl ZstdBufferWithSegments {
}

Ok(Self {
source: data.into_py(py),
source: data.into_py_any(py).unwrap(),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be .into_py_any(py)?

Copy link
Copy Markdown
Contributor Author

@clin1234 clin1234 Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn into_py_any(self, py: Python<'py>)

returns PyResult<Py<PyAny>>, which is defined as a Result type. Since the previous into_py returned a bare PyObject without any checks for the Err result, the unwrap() seems fine.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ? out of principle. The unwrap() forces people to reason about its existence which just adds to the maintenance burden.

buffer: data_buffer,
segments,
})
Expand Down Expand Up @@ -344,7 +344,7 @@ impl ZstdBufferWithSegmentsCollection {

offset += segment.segments.len();

buffers.push(item.to_object(py));
buffers.push(item.into_py_any(py).unwrap());
first_elements.push(offset);
}

Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/compression_chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::CCtx,
},
pyo3::{prelude::*, types::PyBytes},
pyo3::{prelude::*, types::PyBytes, IntoPyObjectExt},
std::sync::Arc,
};

Expand Down Expand Up @@ -225,7 +225,7 @@ impl ZstdCompressionChunkerIterator {
let chunk = PyBytes::new(py, &slf.dest_buffer);
slf.dest_buffer.clear();

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Else continue to compress available input data.
Expand Down Expand Up @@ -278,6 +278,6 @@ impl ZstdCompressionChunkerIterator {
let chunk = PyBytes::new(py, &slf.dest_buffer);
slf.dest_buffer.clear();

Ok(Some(chunk.into_py(py)))
Ok(Some(chunk.into_py_any(py).unwrap()))
}
}
4 changes: 2 additions & 2 deletions rust-ext/src/compression_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
buffer::PyBuffer,
exceptions::{PyNotImplementedError, PyOSError, PyValueError},
prelude::*,
types::PyBytes,
types::PyBytes, IntoPyObjectExt,
},
std::sync::Arc,
};
Expand Down Expand Up @@ -48,7 +48,7 @@ impl ZstdCompressionWriter {

Ok(Self {
cctx,
writer: writer.into_py(py),
writer: writer.into_py_any(py).unwrap(),
write_return_read,
closefd,
entered: false,
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/compressor_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::CCtx,
},
pyo3::{prelude::*, types::PyBytes},
pyo3::{prelude::*, types::PyBytes, IntoPyObjectExt},
std::sync::Arc,
};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl ZstdCompressorIterator {
// TODO avoid buffer copy
let chunk = PyBytes::new(py, &dest_buffer);

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Else read another chunk in hopes of producing output data.
Expand Down Expand Up @@ -94,7 +94,7 @@ impl ZstdCompressorIterator {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions rust-ext/src/decompression_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
buffer::PyBuffer,
exceptions::{PyOSError, PyValueError},
prelude::*,
types::PyBytes,
types::PyBytes, IntoPyObjectExt,
},
std::sync::Arc,
};
Expand Down Expand Up @@ -40,7 +40,7 @@ impl ZstdDecompressionWriter {
) -> PyResult<Self> {
Ok(Self {
dctx,
writer: writer.into_py(py),
writer: writer.into_py_any(py).unwrap(),
write_size,
write_return_read,
closefd,
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/decompressor_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::DCtx,
},
pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes},
pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes, IntoPyObjectExt},
std::{cmp::min, sync::Arc},
};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl ZstdDecompressorIterator {
if !dest_buffer.is_empty() {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);
return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Repeat loop to collect more input data.
Expand All @@ -71,7 +71,7 @@ impl ZstdDecompressorIterator {
if !dest_buffer.is_empty() {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);
Ok(Some(chunk.into_py(py)))
Ok(Some(chunk.into_py_any(py).unwrap()))
} else {
Ok(None)
}
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// of the BSD license. See the LICENSE file for details.

use {
pyo3::{buffer::PyBuffer, exceptions::PyValueError, prelude::*},
pyo3::{buffer::PyBuffer, exceptions::PyValueError, prelude::*, IntoPyObjectExt},
zstd_sys::ZSTD_inBuffer,
};

Expand Down Expand Up @@ -139,7 +139,7 @@ pub(crate) fn make_in_buffer_source(
) -> PyResult<Box<dyn InBufferSource + Send>> {
if source.hasattr("read")? {
Ok(Box::new(ReadSource {
source: source.into_py(py),
source: source.into_py_any(py).unwrap(),
buffer: None,
read_size,
finished: false,
Expand All @@ -153,7 +153,7 @@ pub(crate) fn make_in_buffer_source(
})?;

Ok(Box::new(BufferSource {
source: source.into_py(py),
source: source.into_py_any(py).unwrap(),
buffer,
offset: 0,
}))
Expand Down
Loading