Skip to content

Commit f1938d4

Browse files
committed
Further cleanup to imports
1 parent 914a03d commit f1938d4

File tree

4 files changed

+50
-36
lines changed

4 files changed

+50
-36
lines changed

src/class/basic.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
1111
use crate::callback::HashCallbackOutput;
1212
use crate::class::methods::PyMethodDef;
13-
use crate::pycell::PyCell;
1413
use crate::err::{PyErr, PyResult};
1514
use crate::gil::GILPool;
1615
use crate::objectprotocol::ObjectProtocol;
16+
use crate::pycell::PyCell;
1717
use crate::types::PyAny;
18-
use crate::{callback, catch_unwind, exceptions, ffi, FromPyObject, IntoPy, PyClass, PyObject, Python};
18+
use crate::{
19+
callback, catch_unwind, exceptions, ffi, FromPyObject, IntoPy, PyClass, PyObject, Python,
20+
};
1921
use std::os::raw::c_int;
2022

2123
/// Operators for the __richcmp__ method
@@ -487,16 +489,17 @@ where
487489
where
488490
T: for<'p> PyObjectRichcmpProtocol<'p>,
489491
{
490-
let py = crate::Python::assume_gil_acquired();
491-
crate::catch_unwind!(py, {
492+
let py = Python::assume_gil_acquired();
493+
catch_unwind!(py, {
494+
let _pool = GILPool::new(py);
492495
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
493496
let arg = py.from_borrowed_ptr::<PyAny>(arg);
494497

495498
let borrowed_slf = slf.try_borrow()?;
496499
let op = extract_op(op)?;
497500
let arg = arg.extract()?;
498501
let result = borrowed_slf.__richcmp__(arg, op).into();
499-
crate::callback::convert(py, result)
502+
callback::convert(py, result)
500503
})
501504
}
502505
Some(wrap::<T>)

src/class/buffer.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! c-api
77
use crate::err::PyResult;
88
use crate::gil::GILPool;
9-
use crate::{callback, catch_unwind, ffi, PyClass, PyCell, PyRefMut, Python};
9+
use crate::{callback, catch_unwind, ffi, PyCell, PyClass, PyRefMut, Python};
1010
use std::os::raw::c_int;
1111

1212
/// Buffer protocol interface
@@ -126,14 +126,11 @@ where
126126
where
127127
T: for<'p> PyBufferReleaseBufferProtocol<'p>,
128128
{
129-
let py = crate::Python::assume_gil_acquired();
130-
crate::catch_unwind!(py, {
131-
let _pool = crate::GILPool::new(py);
129+
let py = Python::assume_gil_acquired();
130+
catch_unwind!(py, {
131+
let _pool = GILPool::new(py);
132132
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
133-
let result = slf
134-
.try_borrow_mut()
135-
.map_err(crate::PyErr::from)
136-
.and_then(|slf_mut| T::bf_releasebuffer(slf_mut, arg1).into());
133+
let result = T::bf_releasebuffer(slf.try_borrow_mut()?, arg1).into();
137134
crate::callback::convert(py, result)
138135
})
139136
}

src/class/macros.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ macro_rules! py_ternary_func {
185185
$crate::catch_unwind!(py, {
186186
let _pool = $crate::GILPool::new(py);
187187
let slf = py.from_borrowed_ptr::<$crate::PyCell<T>>(slf);
188-
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1).extract()?;
189-
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2).extract()?;
188+
let arg1 = py
189+
.from_borrowed_ptr::<$crate::types::PyAny>(arg1)
190+
.extract()?;
191+
let arg2 = py
192+
.from_borrowed_ptr::<$crate::types::PyAny>(arg2)
193+
.extract()?;
190194

191195
$crate::callback::convert(py, slf.try_borrow()?.$f(arg1, arg2).into())
192196
})
@@ -216,9 +220,15 @@ macro_rules! py_ternary_num_func {
216220
let py = $crate::Python::assume_gil_acquired();
217221
$crate::catch_unwind!(py, {
218222
let _pool = $crate::GILPool::new(py);
219-
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1).extract()?;
220-
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2).extract()?;
221-
let arg3 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg3).extract()?;
223+
let arg1 = py
224+
.from_borrowed_ptr::<$crate::types::PyAny>(arg1)
225+
.extract()?;
226+
let arg2 = py
227+
.from_borrowed_ptr::<$crate::types::PyAny>(arg2)
228+
.extract()?;
229+
let arg3 = py
230+
.from_borrowed_ptr::<$crate::types::PyAny>(arg3)
231+
.extract()?;
222232

223233
let result = $class::$f(arg1, arg2, arg3).into();
224234
$crate::callback::convert(py, result)
@@ -311,7 +321,9 @@ macro_rules! py_func_del {
311321

312322
if value.is_null() {
313323
let slf = py.from_borrowed_ptr::<$crate::PyCell<U>>(slf);
314-
let name = py.from_borrowed_ptr::<$crate::types::PyAny>(name).extract()?;
324+
let name = py
325+
.from_borrowed_ptr::<$crate::types::PyAny>(name)
326+
.extract()?;
315327
$crate::callback::convert(py, slf.try_borrow_mut()?.$fn_del(name).into())
316328
} else {
317329
Err(PyErr::new::<exceptions::NotImplementedError, _>(

src/class/sequence.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
//! Python Sequence Interface
44
//! Trait and support implementation for implementing sequence
55
6+
use crate::conversion::{FromPyObject, IntoPy};
67
use crate::err::{PyErr, PyResult};
8+
use crate::gil::GILPool;
79
use crate::objectprotocol::ObjectProtocol;
810
use crate::types::PyAny;
9-
use crate::{exceptions, ffi, FromPyObject, IntoPy, PyClass, PyObject};
11+
use crate::{callback, catch_unwind, exceptions, ffi, PyCell, PyClass, PyObject, Python};
1012
use std::os::raw::c_int;
1113

1214
/// Sequence interface
@@ -255,10 +257,10 @@ mod sq_ass_item_impl {
255257
where
256258
T: for<'p> PySequenceSetItemProtocol<'p>,
257259
{
258-
let py = crate::Python::assume_gil_acquired();
259-
crate::catch_unwind!(py, {
260-
let _pool = crate::GILPool::new(py);
261-
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
260+
let py = Python::assume_gil_acquired();
261+
catch_unwind!(py, {
262+
let _pool = GILPool::new(py);
263+
let slf = py.from_borrowed_ptr::<PyCell<T>>(slf);
262264

263265
if value.is_null() {
264266
return Err(PyErr::new::<exceptions::NotImplementedError, _>(format!(
@@ -271,7 +273,7 @@ mod sq_ass_item_impl {
271273
let value = py.from_borrowed_ptr::<PyAny>(value);
272274
let value = value.extract()?;
273275
let result = slf.__setitem__(key.into(), value).into();
274-
crate::callback::convert(py, result)
276+
callback::convert(py, result)
275277
})
276278
}
277279
Some(wrap::<T>)
@@ -304,10 +306,10 @@ mod sq_ass_item_impl {
304306
where
305307
T: for<'p> PySequenceDelItemProtocol<'p>,
306308
{
307-
let py = crate::Python::assume_gil_acquired();
308-
crate::catch_unwind!(py, {
309-
let _pool = crate::GILPool::new(py);
310-
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
309+
let py = Python::assume_gil_acquired();
310+
catch_unwind!(py, {
311+
let _pool = GILPool::new(py);
312+
let slf = py.from_borrowed_ptr::<PyCell<T>>(slf);
311313

312314
let result = if value.is_null() {
313315
slf.borrow_mut().__delitem__(key.into()).into()
@@ -318,7 +320,7 @@ mod sq_ass_item_impl {
318320
)))
319321
};
320322

321-
crate::callback::convert(py, result)
323+
callback::convert(py, result)
322324
})
323325
}
324326
Some(wrap::<T>)
@@ -351,10 +353,10 @@ mod sq_ass_item_impl {
351353
where
352354
T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>,
353355
{
354-
let py = crate::Python::assume_gil_acquired();
355-
crate::catch_unwind!(py, {
356-
let _pool = crate::GILPool::new(py);
357-
let slf = py.from_borrowed_ptr::<crate::PyCell<T>>(slf);
356+
let py = Python::assume_gil_acquired();
357+
catch_unwind!(py, {
358+
let _pool = GILPool::new(py);
359+
let slf = py.from_borrowed_ptr::<PyCell<T>>(slf);
358360

359361
let result = if value.is_null() {
360362
call_mut!(slf, __delitem__; key.into())
@@ -364,7 +366,7 @@ mod sq_ass_item_impl {
364366
let value = value.extract()?;
365367
slf_.__setitem__(key.into(), value).into()
366368
};
367-
crate::callback::convert(py, result)
369+
callback::convert(py, result)
368370
})
369371
}
370372
Some(wrap::<T>)
@@ -459,7 +461,7 @@ where
459461
py_binary_func!(
460462
PySequenceInplaceConcatProtocol,
461463
T::__inplace_concat__,
462-
*mut crate::ffi::PyObject,
464+
*mut ffi::PyObject,
463465
call_mut
464466
)
465467
}

0 commit comments

Comments
 (0)