Skip to content

Commit c122896

Browse files
authored
Merge pull request #163 from davidhewitt/pyo3-macro-tidys
Update to PyO3 0.13
2 parents 49ac8e6 + 20b44fe commit c122896

File tree

7 files changed

+15
-22
lines changed

7 files changed

+15
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- Unreleased
44
- Bump num-complex to 0.3
55
- Bump ndarray to 0.14
6+
- Bump pyo3 to 0.13
7+
- Drop support for Python 3.5 (as it is now end-of-life).
8+
- Remove unused `python3` feature
69

710
- v0.12.1
811
- Fix compile error in Rust 1.39

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ libc = "0.2"
1515
num-complex = "0.3"
1616
num-traits = "0.2"
1717
ndarray = "0.14"
18-
pyo3 = ">=0.12"
18+
pyo3 = "0.13"
1919

2020
[features]
2121
# In default setting, python version is automatically detected
2222
default = []
23-
# This is no longer needed but setuptools-rust assumes this feature
24-
python3 = ["pyo3/python3"]
2523

2624

2725
[workspace]

examples/linalg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ ndarray = "0.14"
1414
ndarray-linalg = { git = "https://github.com/kngwyu/ndarray-linalg", branch = "ndarray-014", features = ["openblas-static"] }
1515

1616
[dependencies.pyo3]
17-
version = "0.12"
17+
version = "0.13"
1818
features = ["extension-module"]

examples/simple-extension/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
numpy = { path = "../.." }
13-
ndarray = ">= 0.12"
13+
ndarray = "0.14"
1414

1515
[dependencies.pyo3]
16-
version = "0.12"
16+
version = "0.13"
1717
features = ["extension-module"]

src/array.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,17 @@ pub fn get_array_module(py: Python<'_>) -> PyResult<&PyModule> {
101101
unsafe impl<T, D> type_object::PyLayout<PyArray<T, D>> for npyffi::PyArrayObject {}
102102
impl<T, D> type_object::PySizedLayout<PyArray<T, D>> for npyffi::PyArrayObject {}
103103

104-
pyobject_native_type_convert!(
104+
pyobject_native_type_info!(
105105
PyArray<T, D>,
106106
npyffi::PyArrayObject,
107107
*npyffi::PY_ARRAY_API.get_type_object(npyffi::NpyTypes::PyArray_Type),
108108
Some("numpy"),
109-
npyffi::PyArray_Check,
110-
T, D
109+
npyffi::PyArray_Check
110+
; T
111+
; D
111112
);
112113

113-
pyobject_native_type_named!(PyArray<T, D>, T, D);
114-
pyobject_native_type_fmt!(PyArray<T, D>, T, D);
115-
116-
impl<'a, T, D> std::convert::From<&'a PyArray<T, D>> for &'a PyAny {
117-
fn from(ob: &'a PyArray<T, D>) -> Self {
118-
unsafe { &*(ob as *const PyArray<T, D> as *const PyAny) }
119-
}
120-
}
114+
pyobject_native_type_named!(PyArray<T, D> ; T ; D);
121115

122116
impl<T, D> IntoPy<PyObject> for PyArray<T, D> {
123117
fn into_py(self, py: Python<'_>) -> PyObject {

src/dtype.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ pyobject_native_type_core!(
3232
arraydescr_check
3333
);
3434

35-
pyobject_native_type_fmt!(PyArrayDescr);
36-
3735
unsafe fn arraydescr_check(op: *mut ffi::PyObject) -> c_int {
3836
ffi::PyObject_TypeCheck(
3937
op,
@@ -54,7 +52,7 @@ impl PyArrayDescr {
5452
/// pyo3::Python::with_gil(|py| {
5553
/// let array = numpy::PyArray::from_vec(py, vec![0.0, 1.0, 2.0f64]);
5654
/// let dtype = array.dtype();
57-
/// assert_eq!(dtype.get_type().name().to_string(), "numpy.float64");
55+
/// assert_eq!(dtype.get_type().name().unwrap().to_string(), "float64");
5856
/// });
5957
/// ```
6058
pub fn get_type(&self) -> &PyType {

tests/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ fn as_slice() {
110110
fn is_instance() {
111111
pyo3::Python::with_gil(|py| {
112112
let arr = PyArray2::<f64>::new(py, [3, 5], false);
113-
assert!(py.is_instance::<PyArray2<f64>, _>(arr).unwrap());
114-
assert!(!py.is_instance::<PyList, _>(arr).unwrap());
113+
assert!(arr.is_instance::<PyArray2<f64>>().unwrap());
114+
assert!(!arr.is_instance::<PyList>().unwrap());
115115
})
116116
}
117117

0 commit comments

Comments
 (0)