Skip to content

Commit f6cea08

Browse files
committed
rust: replace deprecated *bound functions
This accounts for most of the deprecation warnings after the 0.23 PyO3 upgrade.
1 parent 473ceec commit f6cea08

20 files changed

Lines changed: 137 additions & 137 deletions

rust-ext/src/buffers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl ZstdBufferSegment {
8383
}
8484

8585
fn tobytes<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyBytes>> {
86-
Ok(PyBytes::new_bound(py, self.as_slice()))
86+
Ok(PyBytes::new(py, self.as_slice()))
8787
}
8888
}
8989

@@ -179,7 +179,7 @@ impl ZstdBufferWithSegments {
179179

180180
Ok(ZstdBufferSegment {
181181
_parent: self.source.clone_ref(py),
182-
buffer: PyBuffer::get_bound(self.source.downcast_bound(py)?)?,
182+
buffer: PyBuffer::get(self.source.downcast_bound(py)?)?,
183183
offset: segment.offset as _,
184184
len: segment.length as _,
185185
})
@@ -211,7 +211,7 @@ impl ZstdBufferWithSegments {
211211

212212
#[new]
213213
pub fn new(py: Python, data: &Bound<'_, PyAny>, segments: PyBuffer<u8>) -> PyResult<Self> {
214-
let data_buffer = PyBuffer::get_bound(&data.as_borrowed())?;
214+
let data_buffer = PyBuffer::get(&data.as_borrowed())?;
215215

216216
if segments.len_bytes() % std::mem::size_of::<BufferSegment>() != 0 {
217217
return Err(PyValueError::new_err(format!(
@@ -261,7 +261,7 @@ impl ZstdBufferWithSegments {
261261
}
262262

263263
fn tobytes<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyBytes>> {
264-
Ok(PyBytes::new_bound(py, self.as_slice()))
264+
Ok(PyBytes::new(py, self.as_slice()))
265265
}
266266
}
267267

rust-ext/src/compression_chunker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl ZstdCompressionChunker {
119119
}
120120

121121
let source =
122-
make_in_buffer_source(py, &PyBytes::new_bound(py, &[]), zstd_safe::CCtx::in_size())?;
122+
make_in_buffer_source(py, &PyBytes::new(py, &[]), zstd_safe::CCtx::in_size())?;
123123

124124
let it = Bound::new(
125125
py,
@@ -153,7 +153,7 @@ impl ZstdCompressionChunker {
153153
}
154154

155155
let source =
156-
make_in_buffer_source(py, &PyBytes::new_bound(py, &[]), zstd_safe::CCtx::in_size())?;
156+
make_in_buffer_source(py, &PyBytes::new(py, &[]), zstd_safe::CCtx::in_size())?;
157157

158158
let it = Bound::new(
159159
py,
@@ -222,7 +222,7 @@ impl ZstdCompressionChunkerIterator {
222222

223223
// If we produced a full output chunk, emit it.
224224
if slf.dest_buffer.len() == slf.dest_buffer.capacity() {
225-
let chunk = PyBytes::new_bound(py, &slf.dest_buffer);
225+
let chunk = PyBytes::new(py, &slf.dest_buffer);
226226
slf.dest_buffer.clear();
227227

228228
return Ok(Some(chunk.into_py(py)));
@@ -275,7 +275,7 @@ impl ZstdCompressionChunkerIterator {
275275
slf.finished = true;
276276
}
277277

278-
let chunk = PyBytes::new_bound(py, &slf.dest_buffer);
278+
let chunk = PyBytes::new(py, &slf.dest_buffer);
279279
slf.dest_buffer.clear();
280280

281281
Ok(Some(chunk.into_py(py)))

rust-ext/src/compression_dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ZstdCompressionDict {
120120
}
121121

122122
fn as_bytes<'p>(&self, py: Python<'p>) -> PyResult<Bound<'p, PyBytes>> {
123-
Ok(PyBytes::new_bound(py, &self.data))
123+
Ok(PyBytes::new(py, &self.data))
124124
}
125125

126126
fn dict_id(&self) -> u32 {

rust-ext/src/compression_parameters.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl ZstdCompressionParameters {
404404
let kwargs = if let Some(v) = kwargs {
405405
v.copy()?
406406
} else {
407-
PyDict::new_bound(py)
407+
PyDict::new(py)
408408
};
409409

410410
let level = args.get_item(0)?.extract::<i32>()?;
@@ -448,7 +448,7 @@ impl ZstdCompressionParameters {
448448
kwargs.set_item("strategy", compression_params.strategy as u32)?;
449449
}
450450

451-
Self::new(py, &PyTuple::empty_bound(py), Some(&kwargs))
451+
Self::new(py, &PyTuple::empty(py), Some(&kwargs))
452452
}
453453

454454
#[new]
@@ -468,7 +468,7 @@ impl ZstdCompressionParameters {
468468
let kwargs = if let Some(v) = kwargs {
469469
v.copy()?
470470
} else {
471-
PyDict::new_bound(py)
471+
PyDict::new(py)
472472
};
473473

474474
instance.set_parameters(&kwargs)?;

rust-ext/src/compression_reader.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,18 @@ impl ZstdCompressionReader {
117117

118118
fn __iter__(slf: PyRef<Self>) -> PyResult<()> {
119119
let py = slf.py();
120-
let io = py.import_bound("io")?;
120+
let io = py.import("io")?;
121121
let exc = io.getattr("UnsupportedOperation")?;
122122

123-
Err(PyErr::from_value_bound(exc))
123+
Err(PyErr::from_value(exc))
124124
}
125125

126126
fn __next__(slf: PyRef<Self>) -> PyResult<Option<()>> {
127127
let py = slf.py();
128-
let io = py.import_bound("io")?;
128+
let io = py.import("io")?;
129129
let exc = io.getattr("UnsupportedOperation")?;
130130

131-
Err(PyErr::from_value_bound(exc))
131+
Err(PyErr::from_value(exc))
132132
}
133133

134134
fn __enter__<'p>(mut slf: PyRefMut<'p, Self>, _py: Python<'p>) -> PyResult<PyRefMut<'p, Self>> {
@@ -170,19 +170,19 @@ impl ZstdCompressionReader {
170170
}
171171

172172
fn readline(&self, py: Python) -> PyResult<()> {
173-
let io = py.import_bound("io")?;
173+
let io = py.import("io")?;
174174
let exc = io.getattr("UnsupportedOperation")?;
175175

176-
Err(PyErr::from_value_bound(exc))
176+
Err(PyErr::from_value(exc))
177177
}
178178

179179
#[pyo3(signature = (hint=None))]
180180
#[allow(unused_variables)]
181181
fn readlines(&self, py: Python, hint: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
182-
let io = py.import_bound("io")?;
182+
let io = py.import("io")?;
183183
let exc = io.getattr("UnsupportedOperation")?;
184184

185-
Err(PyErr::from_value_bound(exc))
185+
Err(PyErr::from_value(exc))
186186
}
187187

188188
fn write(&self, _data: &Bound<'_, PyAny>) -> PyResult<()> {
@@ -227,7 +227,7 @@ impl ZstdCompressionReader {
227227
}
228228

229229
fn readall<'p>(&mut self, py: Python<'p>) -> PyResult<Bound<'p, PyAny>> {
230-
let chunks = PyList::empty_bound(py);
230+
let chunks = PyList::empty(py);
231231

232232
loop {
233233
let chunk = self.read(py, 1048576)?;
@@ -239,7 +239,7 @@ impl ZstdCompressionReader {
239239
chunks.append(chunk)?;
240240
}
241241

242-
let empty = PyBytes::new_bound(py, &[]);
242+
let empty = PyBytes::new(py, &[]);
243243

244244
empty.call_method1("join", (chunks,))
245245
}
@@ -261,7 +261,7 @@ impl ZstdCompressionReader {
261261
}
262262

263263
if self.finished_output || size == 0 {
264-
return Ok(PyBytes::new_bound(py, &[]).into_any());
264+
return Ok(PyBytes::new(py, &[]).into_any());
265265
}
266266

267267
let mut dest_buffer: Vec<u8> = Vec::with_capacity(size as _);
@@ -270,7 +270,7 @@ impl ZstdCompressionReader {
270270
// If the output buffer is full, return its content.
271271
if self.compress_into_vec(py, &mut dest_buffer)? {
272272
// TODO avoid buffer copy.
273-
return Ok(PyBytes::new_bound(py, &dest_buffer).into_any());
273+
return Ok(PyBytes::new(py, &dest_buffer).into_any());
274274
}
275275
// Else continue to read new input into the compressor.
276276
}
@@ -302,7 +302,7 @@ impl ZstdCompressionReader {
302302
}
303303

304304
// TODO avoid buffer copy.
305-
Ok(PyBytes::new_bound(py, &dest_buffer).into_any())
305+
Ok(PyBytes::new(py, &dest_buffer).into_any())
306306
}
307307

308308
#[pyo3(signature = (size=-1))]
@@ -318,7 +318,7 @@ impl ZstdCompressionReader {
318318
}
319319

320320
if self.finished_output || size == 0 {
321-
return Ok(PyBytes::new_bound(py, &[]).into_any());
321+
return Ok(PyBytes::new(py, &[]).into_any());
322322
}
323323

324324
// -1 returns arbitrary number of bytes.
@@ -350,7 +350,7 @@ impl ZstdCompressionReader {
350350
|| (!dest_buffer.is_empty() && !self.source.finished())
351351
{
352352
// TODO avoid buffer copy.
353-
return Ok(PyBytes::new_bound(py, &dest_buffer).into_any());
353+
return Ok(PyBytes::new(py, &dest_buffer).into_any());
354354
}
355355

356356
// Input must be exhausted. Finish the compression stream.
@@ -380,7 +380,7 @@ impl ZstdCompressionReader {
380380
}
381381

382382
// TODO avoid buffer copy
383-
Ok(PyBytes::new_bound(py, &dest_buffer).into_any())
383+
Ok(PyBytes::new(py, &dest_buffer).into_any())
384384
}
385385

386386
fn readinto(&mut self, py: Python, buffer: PyBuffer<u8>) -> PyResult<usize> {

rust-ext/src/compression_writer.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ impl ZstdCompressionWriter {
6666

6767
fn __iter__(slf: PyRef<Self>) -> PyResult<()> {
6868
let py = slf.py();
69-
let io = py.import_bound("io")?;
69+
let io = py.import("io")?;
7070
let exc = io.getattr("UnsupportedOperation")?;
7171

72-
Err(PyErr::from_value_bound(exc))
72+
Err(PyErr::from_value(exc))
7373
}
7474

7575
fn __next__(slf: PyRef<Self>) -> PyResult<Option<()>> {
7676
let py = slf.py();
77-
let io = py.import_bound("io")?;
77+
let io = py.import("io")?;
7878
let exc = io.getattr("UnsupportedOperation")?;
7979

80-
Err(PyErr::from_value_bound(exc))
80+
Err(PyErr::from_value(exc))
8181
}
8282

8383
fn __enter__<'p>(mut slf: PyRefMut<'p, Self>, _py: Python<'p>) -> PyResult<PyRefMut<'p, Self>> {
@@ -158,28 +158,28 @@ impl ZstdCompressionWriter {
158158
#[pyo3(signature = (size=None))]
159159
#[allow(unused_variables)]
160160
fn readline(&self, py: Python, size: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
161-
let io = py.import_bound("io")?;
161+
let io = py.import("io")?;
162162
let exc = io.getattr("UnsupportedOperation")?;
163163

164-
Err(PyErr::from_value_bound(exc))
164+
Err(PyErr::from_value(exc))
165165
}
166166

167167
#[pyo3(signature = (hint=None))]
168168
#[allow(unused_variables)]
169169
fn readlines(&self, py: Python, hint: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
170-
let io = py.import_bound("io")?;
170+
let io = py.import("io")?;
171171
let exc = io.getattr("UnsupportedOperation")?;
172172

173-
Err(PyErr::from_value_bound(exc))
173+
Err(PyErr::from_value(exc))
174174
}
175175

176176
#[pyo3(signature = (pos, whence=None))]
177177
#[allow(unused_variables)]
178178
fn seek(&self, py: Python, pos: isize, whence: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
179-
let io = py.import_bound("io")?;
179+
let io = py.import("io")?;
180180
let exc = io.getattr("UnsupportedOperation")?;
181181

182-
Err(PyErr::from_value_bound(exc))
182+
Err(PyErr::from_value(exc))
183183
}
184184

185185
fn seekable(&self) -> bool {
@@ -189,10 +189,10 @@ impl ZstdCompressionWriter {
189189
#[pyo3(signature = (size=None))]
190190
#[allow(unused_variables)]
191191
fn truncate(&self, py: Python, size: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
192-
let io = py.import_bound("io")?;
192+
let io = py.import("io")?;
193193
let exc = io.getattr("UnsupportedOperation")?;
194194

195-
Err(PyErr::from_value_bound(exc))
195+
Err(PyErr::from_value(exc))
196196
}
197197

198198
fn writable(&self) -> bool {
@@ -207,25 +207,25 @@ impl ZstdCompressionWriter {
207207
#[pyo3(signature = (size=None))]
208208
#[allow(unused_variables)]
209209
fn read(&self, py: Python, size: Option<&Bound<'_, PyAny>>) -> PyResult<()> {
210-
let io = py.import_bound("io")?;
210+
let io = py.import("io")?;
211211
let exc = io.getattr("UnsupportedOperation")?;
212212

213-
Err(PyErr::from_value_bound(exc))
213+
Err(PyErr::from_value(exc))
214214
}
215215

216216
fn readall(&self, py: Python) -> PyResult<()> {
217-
let io = py.import_bound("io")?;
217+
let io = py.import("io")?;
218218
let exc = io.getattr("UnsupportedOperation")?;
219219

220-
Err(PyErr::from_value_bound(exc))
220+
Err(PyErr::from_value(exc))
221221
}
222222

223223
#[allow(unused_variables)]
224224
fn readinto(&self, py: Python, b: &Bound<'_, PyAny>) -> PyResult<()> {
225-
let io = py.import_bound("io")?;
225+
let io = py.import("io")?;
226226
let exc = io.getattr("UnsupportedOperation")?;
227227

228-
Err(PyErr::from_value_bound(exc))
228+
Err(PyErr::from_value(exc))
229229
}
230230

231231
fn write(&mut self, py: Python, buffer: PyBuffer<u8>) -> PyResult<usize> {
@@ -252,7 +252,7 @@ impl ZstdCompressionWriter {
252252

253253
if !self.dest_buffer.is_empty() {
254254
// TODO avoid buffer copy.
255-
let chunk = PyBytes::new_bound(py, &self.dest_buffer);
255+
let chunk = PyBytes::new(py, &self.dest_buffer);
256256
self.writer.call_method1(py, "write", (chunk,))?;
257257

258258
total_write += self.dest_buffer.len();
@@ -299,7 +299,7 @@ impl ZstdCompressionWriter {
299299

300300
if !self.dest_buffer.is_empty() {
301301
// TODO avoid buffer copy.
302-
let chunk = PyBytes::new_bound(py, &self.dest_buffer);
302+
let chunk = PyBytes::new(py, &self.dest_buffer);
303303
self.writer.call_method1(py, "write", (chunk,))?;
304304

305305
total_write += self.dest_buffer.len();

rust-ext/src/compressionobj.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl ZstdCompressionObj {
6565
source = result.1;
6666
}
6767

68-
Ok(PyBytes::new_bound(py, &compressed))
68+
Ok(PyBytes::new(py, &compressed))
6969
}
7070

7171
#[pyo3(signature = (flush_mode=None))]
@@ -111,7 +111,7 @@ impl ZstdCompressionObj {
111111
result.extend(&chunk);
112112

113113
if !call_again {
114-
return Ok(PyBytes::new_bound(py, &result));
114+
return Ok(PyBytes::new(py, &result));
115115
}
116116
}
117117
}

rust-ext/src/compressor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl ZstdCompressor {
173173
.allow_threads(|| cctx.compress(source))
174174
.or_else(|msg| Err(ZstdError::new_err(format!("cannot compress: {}", msg))))?;
175175

176-
Ok(PyBytes::new_bound(py, &data))
176+
Ok(PyBytes::new(py, &data))
177177
}
178178

179179
#[pyo3(signature = (size=None, chunk_size=None))]
@@ -298,7 +298,7 @@ impl ZstdCompressor {
298298

299299
if !chunk.is_empty() {
300300
// TODO avoid buffer copy.
301-
let data = PyBytes::new_bound(py, chunk);
301+
let data = PyBytes::new(py, chunk);
302302
ofh.call_method("write", (data,), None)?;
303303
total_write += chunk.len();
304304
}
@@ -321,7 +321,7 @@ impl ZstdCompressor {
321321

322322
if !chunk.is_empty() {
323323
// TODO avoid buffer copy.
324-
let data = PyBytes::new_bound(py, &chunk);
324+
let data = PyBytes::new(py, &chunk);
325325
ofh.call_method("write", (data,), None)?;
326326
total_write += chunk.len();
327327
}

0 commit comments

Comments
 (0)