Skip to content

Commit 1caf511

Browse files
authored
Merge pull request #313 from PyO3/deny-missing-docs
Consolidate deny-missing-docs and missing-debug-implementations lints.
2 parents 9ba777e + 16b1a30 commit 1caf511

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

src/array.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ use crate::borrow::{PyReadonlyArray, PyReadwriteArray};
2323
use crate::cold;
2424
use crate::convert::{ArrayExt, IntoPyArray, NpyIndex, ToNpyDims, ToPyArray};
2525
use crate::dtype::{Element, PyArrayDescr};
26-
use crate::error::{BorrowError, DimensionalityError, FromVecError, NotContiguousError, TypeError};
26+
use crate::error::{
27+
BorrowError, DimensionalityError, FromVecError, NotContiguousError, TypeError,
28+
DIMENSIONALITY_MISMATCH_ERR, MAX_DIMENSIONALITY_ERR,
29+
};
2730
use crate::npyffi::{self, npy_intp, NPY_ORDER, PY_ARRAY_API};
2831
use crate::slice_container::PySliceContainer;
2932

@@ -358,7 +361,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
358361
/// Same as [shape](#method.shape), but returns `D`
359362
#[inline(always)]
360363
pub fn dims(&self) -> D {
361-
D::from_dimension(&Dim(self.shape())).expect("mismatching dimensions")
364+
D::from_dimension(&Dim(self.shape())).expect(DIMENSIONALITY_MISMATCH_ERR)
362365
}
363366

364367
/// Creates a new uninitialized PyArray in python heap.
@@ -838,12 +841,9 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
838841
itemsize: usize,
839842
mut data_ptr: *mut u8,
840843
) -> (StrideShape<D>, u32, *mut u8) {
841-
let shape = D::from_dimension(&Dim(shape)).expect("mismatching dimensions");
844+
let shape = D::from_dimension(&Dim(shape)).expect(DIMENSIONALITY_MISMATCH_ERR);
842845

843-
assert!(
844-
strides.len() <= 32,
845-
"Only dimensionalities of up to 32 are supported"
846-
);
846+
assert!(strides.len() <= 32, "{}", MAX_DIMENSIONALITY_ERR);
847847

848848
let mut new_strides = D::zeros(strides.len());
849849
let mut inverted_axes = 0_u32;

src/borrow.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
//! More involved cases like the example from above may be supported in the future.
160160
//!
161161
//! [base]: https://numpy.org/doc/stable/reference/c-api/types-and-structures.html#c.NPY_AO.base
162-
#![deny(missing_docs)]
163162
164163
use std::any::type_name;
165164
use std::cell::UnsafeCell;

src/convert.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Defines conversion traits between Rust types and NumPy data types.
2-
#![deny(missing_docs)]
32
43
use std::{mem, os::raw::c_int, ptr};
54

@@ -8,6 +7,7 @@ use pyo3::Python;
87

98
use crate::array::PyArray;
109
use crate::dtype::Element;
10+
use crate::error::MAX_DIMENSIONALITY_ERR;
1111
use crate::npyffi::{self, npy_intp};
1212
use crate::sealed::Sealed;
1313

@@ -184,10 +184,7 @@ where
184184
let strides = self.strides();
185185
let itemsize = mem::size_of::<A>() as isize;
186186

187-
assert!(
188-
strides.len() <= 32,
189-
"Only dimensionalities of up to 32 are supported"
190-
);
187+
assert!(strides.len() <= 32, "{}", MAX_DIMENSIONALITY_ERR);
191188

192189
let mut new_strides = [0; 32];
193190

src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ use pyo3::{exceptions::PyTypeError, PyErr, PyErrArguments, PyObject, Python, ToP
77

88
use crate::dtype::PyArrayDescr;
99

10+
/// Array dimensionality should be limited by [`NPY_MAXDIMS`][NPY_MAXDIMS] which is currently 32.´
11+
///
12+
/// [NPY_MAXDIMS]: https://github.com/numpy/numpy/blob/4c60b3263ac50e5e72f6a909e156314fc3c9cba0/numpy/core/include/numpy/ndarraytypes.h#L40
13+
pub(crate) const MAX_DIMENSIONALITY_ERR: &str = "unexpected dimensionality: NumPy is expected to limit arrays to 32 or fewer dimensions.\nPlease report a bug against the `rust-numpy` crate.";
14+
15+
pub(crate) const DIMENSIONALITY_MISMATCH_ERR: &str = "inconsistent dimensionalities: The dimensionality expected by `PyArray` does not match that given by NumPy.\nPlease report a bug against the `rust-numpy` crate.";
16+
1017
macro_rules! impl_pyerr {
1118
($err_type:ty) => {
1219
impl Error for $err_type {}
@@ -120,7 +127,9 @@ impl_pyerr!(NotContiguousError);
120127
#[derive(Debug)]
121128
#[non_exhaustive]
122129
pub enum BorrowError {
130+
/// The given array is already borrowed
123131
AlreadyBorrowed,
132+
/// The given array is not writeable
124133
NotWriteable,
125134
}
126135

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//! [c-api]: https://numpy.org/doc/stable/reference/c-api
3333
//! [ndarray]: https://numpy.org/doc/stable/reference/arrays.ndarray.html
3434
35+
#![deny(missing_docs, missing_debug_implementations)]
3536
// We often want to make the GIL lifetime explicit.
3637
#![allow(clippy::needless_lifetimes)]
3738

src/npyffi/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! <https://numpy.org/doc/stable/reference/c-api>
44
#![allow(
55
non_camel_case_types,
6+
missing_docs,
7+
missing_debug_implementations,
68
clippy::too_many_arguments,
79
clippy::missing_safety_doc
810
)]

src/npyiter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![deprecated(
1717
note = "The wrappers of the array iterator API are deprecated, please use ndarray's iterators like `Lanes` and `Zip` instead."
1818
)]
19+
#![allow(missing_debug_implementations)]
1920

2021
use std::marker::PhantomData;
2122
use std::os::raw::{c_char, c_int};
@@ -48,15 +49,25 @@ use crate::sealed::Sealed;
4849
/// [iterator]: https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NpyIter_MultiNew
4950
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5051
pub enum NpyIterFlag {
52+
/// [`NPY_ITER_COMMON_DTYPE`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_COMMON_DTYPE)
5153
CommonDtype,
54+
/// [`NPY_ITER_REFS_OK`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_REFS_OK)
5255
RefsOk,
56+
/// [`NPY_ITER_ZEROSIZE_OK`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_ZEROSIZE_OK)
5357
ZerosizeOk,
58+
/// [`NPY_ITER_REDUCE_OK`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_REDUCE_OK)
5459
ReduceOk,
60+
/// [`NPY_ITER_RANGED`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_RANGED)
5561
Ranged,
62+
/// [`NPY_ITER_BUFFERED`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_BUFFERED)
5663
Buffered,
64+
/// [`NPY_ITER_GROWINNER`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_GROWINNER)
5765
GrowInner,
66+
/// [`NPY_ITER_DELAY_BUFALLOC`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_DELAY_BUFALLOC)
5867
DelayBufAlloc,
68+
/// [`NPY_ITER_DONT_NEGATE_STRIDES`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_DONT_NEGATE_STRIDES)
5969
DontNegateStrides,
70+
/// [`NPY_ITER_COPY_IF_OVERLAP`](https://numpy.org/doc/stable/reference/c-api/iterator.html#c.NPY_ITER_COPY_IF_OVERLAP)
6071
CopyIfOverlap,
6172
// CIndex,
6273
// FIndex,
@@ -91,8 +102,11 @@ mod itermode {
91102

92103
/// A combinator type that represents the mode of an iterator.
93104
pub trait MultiIterMode: Sealed {
105+
#[doc(hidden)]
94106
type Pre: MultiIterMode;
107+
#[doc(hidden)]
95108
const FLAG: npy_uint32 = 0;
109+
#[doc(hidden)]
96110
fn flags() -> Vec<npy_uint32> {
97111
if Self::FLAG == 0 {
98112
Vec::new()

0 commit comments

Comments
 (0)