Skip to content

Commit 5bea2a8

Browse files
committed
Use existing constructor instead of adding a static method. Thanks @Skylion007 for pointing out.
1 parent d53a796 commit 5bea2a8

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

include/pybind11/numpy.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ class dtype : public object {
564564
m_ptr = from_args(args).release().ptr();
565565
}
566566

567+
/// Return dtype for the given typenum (one of the NPY_TYPES).
568+
/// https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_DescrFromType
567569
explicit dtype(int typenum)
568570
: object(detail::npy_api::get().PyArray_DescrFromType_(typenum), stolen_t{}) {
569571
if (m_ptr == nullptr) {
@@ -586,16 +588,6 @@ class dtype : public object {
586588
return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::dtype();
587589
}
588590

589-
/// Return dtype for the given typenum (one of the NPY_TYPES).
590-
/// https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_DescrFromType
591-
static dtype from_typenum(int typenum) {
592-
auto *ptr = detail::npy_api::get().PyArray_DescrFromType_(typenum);
593-
if (!ptr) {
594-
throw error_already_set();
595-
}
596-
return reinterpret_steal<dtype>(ptr);
597-
}
598-
599591
/// Size of the data type in bytes.
600592
ssize_t itemsize() const { return detail::array_descriptor_proxy(m_ptr)->elsize; }
601593

@@ -1293,7 +1285,7 @@ struct npy_format_descriptor<
12931285
public:
12941286
static constexpr int value = values[detail::is_fmt_numeric<T>::index];
12951287

1296-
static pybind11::dtype dtype() { return pybind11::dtype::from_typenum(value); }
1288+
static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
12971289
};
12981290

12991291
template <typename T>
@@ -1302,7 +1294,7 @@ struct npy_format_descriptor<T, enable_if_t<is_same_ignoring_cvref<T, PyObject *
13021294

13031295
static constexpr int value = npy_api::NPY_OBJECT_;
13041296

1305-
static pybind11::dtype dtype() { return pybind11::dtype::from_typenum(value); }
1297+
static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
13061298
};
13071299

13081300
#define PYBIND11_DECL_CHAR_FMT \

0 commit comments

Comments
 (0)