Problem
PyO3 0.28 deprecated PyAnyMethods::downcast in favour of Bound::cast / Bound::cast_exact. However, these replacements perform Python type checks only — they do not check the NumPy element dtype. This breaks the standard pattern for runtime dtype dispatch in rust-numpy:
if let Ok(arr) = x.downcast::<PyArrayDyn<f64>>() {
// f64 path
} else if let Ok(arr) = x.downcast::<PyArrayDyn<f32>>() {
// f32 path
}
Using cast_exact instead causes the f64 branch to always succeed regardless of the actual dtype, because both PyArrayDyn and PyArrayDyn share the same Python type (numpy.ndarray). The dtype check is performed inside rust-numpy's downcast hook, not by PyO3 itself.
Current workaround
#![allow(deprecated)] // still using downcast — cast/cast_exact do not check element dtype
Question
What is the intended migration path for dtype-aware dispatch in rust-numpy 0.28? Is there a FromPyObject-based or extract-based pattern that performs the dtype check, or is this a known gap pending a fix?
Environment
- rust-numpy: 0.28.0
- pyo3: 0.28.3
- numpy (Python): 1.26.4
- Python: 3.12
Problem
PyO3 0.28 deprecated
PyAnyMethods::downcastin favour ofBound::cast/Bound::cast_exact. However, these replacements perform Python type checks only — they do not check the NumPy element dtype. This breaks the standard pattern for runtime dtype dispatch in rust-numpy:Using cast_exact instead causes the f64 branch to always succeed regardless of the actual dtype, because both PyArrayDyn and PyArrayDyn share the same Python type (numpy.ndarray). The dtype check is performed inside rust-numpy's downcast hook, not by PyO3 itself.
Current workaround
#![allow(deprecated)] // still using downcast — cast/cast_exact do not check element dtype
Question
What is the intended migration path for dtype-aware dispatch in rust-numpy 0.28? Is there a FromPyObject-based or extract-based pattern that performs the dtype check, or is this a known gap pending a fix?
Environment