Skip to content

Commit

Permalink
Remove PyToken usages from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Nov 12, 2018
1 parent d2ba436 commit fb2349b
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 181 deletions.
8 changes: 2 additions & 6 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ with value of custom class struct. Subclass must call parent's `__new__` method.
#[pyclass]
struct BaseClass {
val1: usize,
token: PyToken,
}

#[pymethods]
impl BaseClass {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()> {
obj.init(|token| BaseClass{val1: 10, token})
obj.init(|_| BaseClass{ val1: 10 })
}

pub fn method(&self) -> PyResult<()> {
Expand All @@ -113,14 +112,13 @@ impl BaseClass {
#[pyclass(extends=BaseClass)]
struct SubClass {
val2: usize,
token: PyToken,
}

#[pymethods]
impl SubClass {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()> {
obj.init(|token| SubClass{val2: 10, token});
obj.init(|_| SubClass{ val2: 10 });
BaseClass::__new__(obj)
}

Expand Down Expand Up @@ -513,7 +511,6 @@ use pyo3::prelude::*;
#[pyclass]
struct ClassWithGCSupport {
obj: Option<PyObject>,
token: PyToken,
}

#[pyproto]
Expand Down Expand Up @@ -562,7 +559,6 @@ use pyo3::prelude::*;
#[pyclass]
struct MyIterator {
iter: Box<Iterator<Item=PyObject> + Send>,
token: PyToken,
}

#[pyproto]
Expand Down
4 changes: 2 additions & 2 deletions pyo3-derive-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ fn wrap_fn_argument<'a>(input: &'a syn::FnArg, name: &'a syn::Ident) -> Option<m
let opt = method::check_arg_ty_and_optional(&name, &cap.ty);
Some(method::FnArg {
name: ident,
mutability: mutability,
by_ref: by_ref,
mutability,
by_ref,
ty: &cap.ty,
optional: opt,
py,
Expand Down
6 changes: 2 additions & 4 deletions src/typeob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ pub const PY_TYPE_FLAG_DICT: usize = 1 << 3;
/// use pyo3::prelude::*;
///
/// #[pyclass]
/// struct MyClass {
/// token: PyToken
/// }
/// struct MyClass { }
///
/// #[pymethods]
/// impl MyClass {
/// #[new]
/// fn __new__(obj: &PyRawObject) -> PyResult<()> {
/// obj.init(|token| MyClass { token })
/// obj.init(|_| MyClass { })
/// }
/// }
/// ```
Expand Down
14 changes: 6 additions & 8 deletions tests/test_arithmetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate pyo3;
use pyo3::class::*;
use pyo3::prelude::*;
use pyo3::types::PyObjectRef;
use pyo3::PyObjectWithToken;

#[macro_use]
mod common;
Expand Down Expand Up @@ -212,9 +211,7 @@ impl PyObjectProtocol for RichComparisons {
}

#[pyclass]
struct RichComparisons2 {
py: PyToken,
}
struct RichComparisons2 {}

#[pyproto]
impl PyObjectProtocol for RichComparisons2 {
Expand All @@ -223,10 +220,11 @@ impl PyObjectProtocol for RichComparisons2 {
}

fn __richcmp__(&self, _other: &PyObjectRef, op: CompareOp) -> PyResult<PyObject> {
let gil = GILGuard::acquire();
match op {
CompareOp::Eq => Ok(true.to_object(self.py())),
CompareOp::Ne => Ok(false.to_object(self.py())),
_ => Ok(self.py().NotImplemented()),
CompareOp::Eq => Ok(true.to_object(gil.python())),
CompareOp::Ne => Ok(false.to_object(gil.python())),
_ => Ok(gil.python().NotImplemented()),
}
}
}
Expand Down Expand Up @@ -263,7 +261,7 @@ fn rich_comparisons_python_3_type_error() {
let gil = Python::acquire_gil();
let py = gil.python();

let c2 = py.init(|t| RichComparisons2 { py: t }).unwrap();
let c2 = py.init(|_| RichComparisons2 {}).unwrap();
py_expect_exception!(py, c2, "c2 < c2", TypeError);
py_expect_exception!(py, c2, "c2 < 1", TypeError);
py_expect_exception!(py, c2, "1 < c2", TypeError);
Expand Down
7 changes: 2 additions & 5 deletions tests/test_buffer_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use pyo3::types::PyDict;
#[pyclass]
struct TestClass {
vec: Vec<u8>,
token: PyToken,
}

#[pyproto]
Expand Down Expand Up @@ -72,9 +71,8 @@ fn test_buffer() {
let py = gil.python();

let t = py
.init(|t| TestClass {
.init(|_| TestClass {
vec: vec![b' ', b'2', b'3'],
token: t,
})
.unwrap();

Expand All @@ -90,9 +88,8 @@ fn test_buffer() {
let py = gil.python();

let t = py
.init(|t| TestClass {
.init(|_| TestClass {
vec: vec![b' ', b'2', b'3'],
token: t,
})
.unwrap();

Expand Down
Loading

0 comments on commit fb2349b

Please sign in to comment.