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

Commit a3f1ad9

Browse files
authored
TYP: minor fixes related to errstate (#29914)
1 parent 107200b commit a3f1ad9

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

numpy/__init__.pyi

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ from numpy._core._ufunc_config import (
292292
getbufsize,
293293
seterrcall,
294294
geterrcall,
295-
_ErrKind,
296-
_ErrCall,
295+
errstate,
297296
)
298297

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

760-
_CallableT = TypeVar("_CallableT", bound=Callable[..., object])
761-
762759
_DTypeT = TypeVar("_DTypeT", bound=dtype)
763760
_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype, default=dtype, covariant=True)
764761
_FlexDTypeT = TypeVar("_FlexDTypeT", bound=dtype[flexible])
@@ -5735,29 +5732,6 @@ permute_dims = transpose
57355732
pow = power
57365733
true_divide = divide
57375734

5738-
class errstate:
5739-
__slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under"
5740-
5741-
def __init__(
5742-
self,
5743-
*,
5744-
call: _ErrCall = ...,
5745-
all: _ErrKind | None = None,
5746-
divide: _ErrKind | None = None,
5747-
over: _ErrKind | None = None,
5748-
under: _ErrKind | None = None,
5749-
invalid: _ErrKind | None = None,
5750-
) -> None: ...
5751-
def __enter__(self) -> None: ...
5752-
def __exit__(
5753-
self,
5754-
exc_type: type[BaseException] | None,
5755-
exc_value: BaseException | None,
5756-
traceback: TracebackType | None,
5757-
/,
5758-
) -> None: ...
5759-
def __call__(self, func: _CallableT) -> _CallableT: ...
5760-
57615735
# TODO: The type of each `__next__` and `iters` return-type depends
57625736
# on the length and dtype of `args`; we can't describe this behavior yet
57635737
# as we lack variadics (PEP 646).

numpy/_core/_ufunc_config.pyi

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
from _typeshed import SupportsWrite
22
from collections.abc import Callable
3-
from typing import Any, Literal, TypeAlias, TypedDict, type_check_only
3+
from types import TracebackType
4+
from typing import Any, Final, Literal, TypeAlias, TypedDict, TypeVar, type_check_only
45

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

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

1121
@type_check_only
1222
class _ErrDict(TypedDict):
@@ -15,6 +25,36 @@ class _ErrDict(TypedDict):
1525
under: _ErrKind
1626
invalid: _ErrKind
1727

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

0 commit comments

Comments
 (0)