Skip to content

Commit 0258e6d

Browse files
committed
call_method0
1 parent 2aa3d90 commit 0258e6d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/random.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! use numpy::random::{PyBitGenerator, PyBitGeneratorMethods as _};
1010
//!
1111
//! let mut bitgen = Python::with_gil(|py| -> PyResult<_> {
12-
//! let default_rng = py.import("numpy.random")?.getattr("default_rng")?.call0()?;
12+
//! let default_rng = py.import("numpy.random")?.call_method0("default_rng")?;
1313
//! let bit_generator = default_rng.getattr("bit_generator")?.downcast_into::<PyBitGenerator>()?;
1414
//! bit_generator.lock()
1515
//! })?;
@@ -83,17 +83,17 @@ impl<'py> PyBitGeneratorMethods for Bound<'py, PyBitGenerator> {
8383
fn lock(&self) -> PyResult<PyBitGeneratorGuard> {
8484
let capsule = self.getattr("capsule")?.downcast_into::<PyCapsule>()?;
8585
let lock = self.getattr("lock")?;
86-
if lock.getattr("locked")?.call0()?.extract()? {
86+
if lock.call_method0("locked")?.extract()? {
8787
return Err(PyRuntimeError::new_err("BitGenerator is already locked"));
8888
}
89-
lock.getattr("acquire")?.call0()?;
89+
lock.call_method0("acquire")?;
9090

9191
assert_eq!(capsule.name()?, Some(c"BitGenerator"));
9292
let ptr = capsule.pointer() as *mut npy_bitgen;
9393
let non_null = match NonNull::new(ptr) {
9494
Some(non_null) => non_null,
9595
None => {
96-
lock.getattr("release")?.call0()?;
96+
lock.call_method0("release")?;
9797
return Err(PyRuntimeError::new_err("Invalid BitGenerator capsule"));
9898
}
9999
};
@@ -153,7 +153,7 @@ impl PyBitGeneratorGuard {
153153
impl Drop for PyBitGeneratorGuard {
154154
fn drop(&mut self) {
155155
let r = Python::with_gil(|py| -> PyResult<()> {
156-
self.lock.bind(py).getattr("release")?.call0()?;
156+
self.lock.bind(py).call_method0("release")?;
157157
Ok(())
158158
});
159159
if let Err(e) = r {
@@ -180,7 +180,7 @@ mod tests {
180180
use super::*;
181181

182182
fn get_bit_generator<'py>(py: Python<'py>) -> PyResult<Bound<'py, PyBitGenerator>> {
183-
let default_rng = py.import("numpy.random")?.getattr("default_rng")?.call0()?;
183+
let default_rng = py.import("numpy.random")?.call_method0("default_rng")?;
184184
let bit_generator = default_rng
185185
.getattr("bit_generator")?
186186
.downcast_into::<PyBitGenerator>()?;
@@ -218,8 +218,7 @@ mod tests {
218218
std::mem::drop(bitgen);
219219
assert!(!generator
220220
.getattr("lock")?
221-
.getattr("locked")?
222-
.call0()?
221+
.call_method0("locked")?
223222
.extract()?);
224223
Ok(())
225224
})

0 commit comments

Comments
 (0)