8000 Added Warning and Exception annotations by BvB93 · Pull Request #57 · numpy/numpy-stubs · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Added Warning and Exception annotations #57

Merged
merged 3 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
16 changes: 15 additions & 1 deletion numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
5 changes: 5 additions & 0 deletions tests/fail/warnings_and_errors.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/pass/warnings_and_errors.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions tests/reveal/warnings_and_errors.py
Original file line number Diff line number Diff line change
@@ -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
0