Skip to content

Commit 7fc47f0

Browse files
committed
Remove deprecated function and align convention for helper function.
1 parent 76fd0fe commit 7fc47f0

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- The `PyArray::resize` function supports n-dimensional contiguous arrays. ([#312](https://github.com/PyO3/rust-numpy/pull/312))
1010
- Deprecate `PyArray::from_exact_iter` after optimizing `PyArray::from_iter`. ([#292](https://github.com/PyO3/rust-numpy/pull/292))
1111
- Remove `DimensionalityError` and `TypeError` from the public API as they never used directly. ([#315](https://github.com/PyO3/rust-numpy/pull/315))
12+
- Remove the deprecated `PyArrayDescr::get_type` which was replaced by `PyArrayDescr::typeobj` in the last cycle. ([#308](https://github.com/PyO3/rust-numpy/pull/308))
1213
- Fix returning invalid slices from `PyArray::{strides,shape}` for rank zero arrays. ([#303](https://github.com/PyO3/rust-numpy/pull/303))
1314

1415
- v0.16.2

src/dtype.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ impl PyArrayDescr {
8484
///
8585
/// [dtype]: https://numpy.org/doc/stable/reference/generated/numpy.dtype.html
8686
#[inline]
87-
pub fn new<'py, T: ToPyObject + ?Sized>(py: Python<'py>, obj: &T) -> PyResult<&'py Self> {
88-
Self::new_impl(py, obj.to_object(py))
89-
}
90-
91-
fn new_impl<'py>(py: Python<'py>, obj: PyObject) -> PyResult<&'py Self> {
92-
let mut descr: *mut PyArray_Descr = ptr::null_mut();
93-
unsafe {
94-
// None is an invalid input here and is not converted to NPY_DEFAULT_TYPE
95-
PY_ARRAY_API.PyArray_DescrConverter2(py, obj.as_ptr(), &mut descr as *mut _);
96-
py.from_owned_ptr_or_err(descr as _)
87+
pub fn new<'py, T: ToPyObject + ?Sized>(py: Python<'py>, ob: &T) -> PyResult<&'py Self> {
88+
fn inner<'py>(py: Python<'py>, obj: PyObject) -> PyResult<&'py PyArrayDescr> {
89+
let mut descr: *mut PyArray_Descr = ptr::null_mut();
90+
unsafe {
91+
// None is an invalid input here and is not converted to NPY_DEFAULT_TYPE
92+
PY_ARRAY_API.PyArray_DescrConverter2(py, obj.as_ptr(), &mut descr as *mut _);
93+
py.from_owned_ptr_or_err(descr as _)
94+
}
9795
}
96+
97+
inner(py, ob.to_object(py))
9898
}
9999

100100
/// Returns `self` as `*mut PyArray_Descr`.
@@ -127,7 +127,7 @@ impl PyArrayDescr {
127127
}
128128
}
129129

130-
fn from_npy_type(py: Python, npy_type: NPY_TYPES) -> &Self {
130+
pub(crate) fn from_npy_type(py: Python, npy_type: NPY_TYPES) -> &Self {
131131
unsafe {
132132
let descr = PY_ARRAY_API.PyArray_DescrFromType(py, npy_type as _);
133133
py.from_owned_ptr(descr as _)
@@ -145,15 +145,6 @@ impl PyArrayDescr {
145145
unsafe { PyType::from_type_ptr(self.py(), dtype_type_ptr) }
146146
}
147147

148-
#[doc(hidden)]
149-
#[deprecated(
150-
since = "0.16.0",
151-
note = "`get_type()` is deprecated, please use `typeobj()` instead"
152-
)]
153-
pub fn get_type(&self) -> &PyType {
154-
self.typeobj()
155-
}
156-
157148
/// Returns a unique number for each of the 21 different built-in
158149
/// [enumerated types][enumerated-types].
159150
///

0 commit comments

Comments
 (0)