🌐 AI搜索 & 代理 主页
Skip to content

Commit 9c9aee2

Browse files
jorenhamcharris
authored andcommitted
TYP: minor fixes related to errstate (#29914)
1 parent 126d15c commit 9c9aee2

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

numpy/__init__.pyi

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ from numpy._core._ufunc_config import (
295295
getbufsize,
296296
seterrcall,
297297
geterrcall,
298-
_ErrKind,
299-
_ErrCall,
298+
errstate,
300299
)
301300

302301
from numpy._core.arrayprint import (
@@ -756,8 +755,6 @@ _T_contra = TypeVar("_T_contra", contravariant=True)
756755
_RealT_co = TypeVar("_RealT_co", covariant=True)
757756
_ImagT_co = TypeVar("_ImagT_co", covariant=True)
758757

759-
_CallableT = TypeVar("_CallableT", bound=Callable[..., object])
760-
761758
_DTypeT = TypeVar("_DTypeT", bound=dtype)
762759
_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype, default=dtype, covariant=True)
763760
_FlexDTypeT = TypeVar("_FlexDTypeT", bound=dtype[flexible])
@@ -5662,29 +5659,6 @@ bitwise_right_shift = right_shift
56625659
permute_dims = transpose
56635660
pow = power
56645661

5665-
class errstate:
5666-
__slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under"
5667-
5668-
def __init__(
5669-
self,
5670-
*,
5671-
call: _ErrCall = ...,
5672-
all: _ErrKind | None = ...,
5673-
divide: _ErrKind | None = ...,
5674-
over: _ErrKind | None = ...,
5675-
under: _ErrKind | None = ...,
5676-
invalid: _ErrKind | None = ...,
5677-
) -> None: ...
5678-
def __enter__(self) -> None: ...
5679-
def __exit__(
5680-
self,
5681-
exc_type: type[BaseException] | None,
5682-
exc_value: BaseException | None,
5683-
traceback: TracebackType | None,
5684-
/,
5685-
) -> None: ...
5686-
def __call__(self, func: _CallableT) -> _CallableT: ...
5687-
56885662
# TODO: The type of each `__next__` and `iters` return-type depends
56895663
# on the length and dtype of `args`; we can't describe this behavior yet
56905664
# as we lack variadics (PEP 646).

numpy/_core/_ufunc_config.pyi

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
from collections.abc import Callable
2-
from typing import Any, Literal, TypeAlias, TypedDict, type_check_only
2+
from types import TracebackType
3+
from typing import Any, Final, Literal, TypeAlias, TypedDict, TypeVar, type_check_only
34

4-
from _typeshed import SupportsWrite
5-
6-
from numpy import errstate as errstate
5+
__all__ = [
6+
"seterr",
7+
"geterr",
8+
"setbufsize",
9+
"getbufsize",
10+
"seterrcall",
11+
"geterrcall",
12+
"errstate",
13+
]
714

815
_ErrKind: TypeAlias = Literal["ignore", "warn", "raise", "call", "print", "log"]
9-
_ErrFunc: TypeAlias = Callable[[str, int], Any]
10-
_ErrCall: TypeAlias = _ErrFunc | SupportsWrite[str]
16+
_ErrCall: TypeAlias = Callable[[str, int], Any] | SupportsWrite[str]
17+
18+
_CallableT = TypeVar("_CallableT", bound=Callable[..., object])
1119

1220
@type_check_only
1321
class _ErrDict(TypedDict):
@@ -16,6 +24,36 @@ class _ErrDict(TypedDict):
1624
under: _ErrKind
1725
invalid: _ErrKind
1826

27+
###
28+
29+
class _unspecified: ...
30+
31+
_Unspecified: Final[_unspecified]
32+
33+
class errstate:
34+
__slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under"
35+
36+
def __init__(
37+
self,
38+
/,
39+
*,
40+
call: _ErrCall | _unspecified = ..., # = _Unspecified
41+
all: _ErrKind | None = None,
42+
divide: _ErrKind | None = None,
43+
over: _ErrKind | None = None,
44+
under: _ErrKind | None = None,
45+
invalid: _ErrKind | None = None,
46+
) -> None: ...
47+
def __call__(self, /, func: _CallableT) -> _CallableT: ...
48+
def __enter__(self) -> None: ...
49+
def __exit__(
50+
self,
51+
exc_type: type[BaseException] | None,
52+
exc_value: BaseException | None,
53+
traceback: TracebackType | None,
54+
/,
55+
) -> None: ...
56+
1957
def seterr(
2058
all: _ErrKind | None = ...,
2159
divide: _ErrKind | None = ...,
@@ -28,5 +66,3 @@ def setbufsize(size: int) -> int: ...
2866
def getbufsize() -> int: ...
2967
def seterrcall(func: _ErrCall | None) -> _ErrCall | None: ...
3068
def geterrcall() -> _ErrCall | None: ...
31-
32-
# See `numpy/__init__.pyi` for the `errstate` class and `no_nep5_warnings`

0 commit comments

Comments
 (0)