diff --git a/numpy-stubs/__init__.pyi b/numpy-stubs/__init__.pyi index 960e6e5..9151ad1 100644 --- a/numpy-stubs/__init__.pyi +++ b/numpy-stubs/__init__.pyi @@ -103,7 +103,7 @@ class dtype: def descr(self) -> List[Union[Tuple[str, str], Tuple[str, str, _Shape]]]: ... @property def fields( - self + self, ) -> Optional[Mapping[str, Union[Tuple[dtype, int], Tuple[dtype, int, Any]]]]: ... @property def flags(self) -> int: ... @@ -778,3 +778,17 @@ trunc: ufunc # TODO(shoyer): remove when the full numpy namespace is defined def __getattr__(name: str) -> Any: ... + +# Warnings +class ModuleDeprecationWarning(DeprecationWarning): ... +class VisibleDeprecationWarning(UserWarning): ... +class ComplexWarning(RuntimeWarning): ... +class RankWarning(UserWarning): ... + +# Errors +class TooHardError(RuntimeError): ... + +class AxisError(ValueError, IndexError): + def __init__( + self, axis: int, ndim: Optional[int] = ..., msg_prefix: Optional[str] = ... + ) -> None: ... diff --git a/tests/fail/warnings_and_errors.py b/tests/fail/warnings_and_errors.py new file mode 100644 index 0000000..9f8b1db --- /dev/null +++ b/tests/fail/warnings_and_errors.py @@ -0,0 +1,5 @@ +import numpy as np + +np.AxisError(1.0) # E: Argument 1 to "AxisError" has incompatible type +np.AxisError(1, ndim=2.0) # E: Argument "ndim" to "AxisError" has incompatible type +np.AxisError(2, msg_prefix=404) # E: Argument "msg_prefix" to "AxisError" has incompatible type diff --git a/tests/pass/warnings_and_errors.py b/tests/pass/warnings_and_errors.py new file mode 100644 index 0000000..e69e1f1 --- /dev/null +++ b/tests/pass/warnings_and_errors.py @@ -0,0 +1,7 @@ +import numpy as np + +np.AxisError(1) +np.AxisError(1, ndim=2) +np.AxisError(1, ndim=None) +np.AxisError(1, ndim=2, msg_prefix='error') +np.AxisError(1, ndim=2, msg_prefix=None) diff --git a/tests/reveal/warnings_and_errors.py b/tests/reveal/warnings_and_errors.py new file mode 100644 index 0000000..c428deb --- /dev/null +++ b/tests/reveal/warnings_and_errors.py @@ -0,0 +1,10 @@ +from typing import Type + +import numpy as np + +reveal_type(np.ModuleDeprecationWarning()) # E: numpy.ModuleDeprecationWarning +reveal_type(np.VisibleDeprecationWarning()) # E: numpy.VisibleDeprecationWarning +reveal_type(np.ComplexWarning()) # E: numpy.ComplexWarning +reveal_type(np.RankWarning()) # E: numpy.RankWarning +reveal_type(np.TooHardError()) # E: numpy.TooHardError +reveal_type(np.AxisError(1)) # E: numpy.AxisError