use &mut self receiver and py args.

This commit is contained in:
mejrs 2021-08-26 15:28:52 +02:00
parent eaf5e6de9c
commit 76179967f3
1 changed files with 6 additions and 6 deletions

View File

@ -620,7 +620,6 @@ as argument and calls that object when called.
```rust
# use pyo3::prelude::*;
# use pyo3::types::{PyDict, PyTuple};
# use pyo3::PyNativeType;
#
#[pyclass(name = "counter")]
struct PyCounter {
@ -638,15 +637,16 @@ impl PyCounter {
#[call]
#[args(args = "*", kwargs = "**")]
fn __call__(
mut slf: PyRefMut<Self>,
&mut self,
py: Python,
args: &PyTuple,
kwargs: Option<&PyDict>,
) -> PyResult<Py<PyAny>> {
slf.count += 1;
let name = slf.wraps.getattr(args.py(), "__name__").unwrap();
self.count += 1;
let name = self.wraps.getattr(py, "__name__").unwrap();
println!("{} has been called {} time(s).", name, slf.count);
slf.wraps.call(args.py(), args, kwargs)
println!("{} has been called {} time(s).", name, self.count);
self.wraps.call(py, args, kwargs)
}
}
```