🌐 AI搜索 & 代理 主页
Skip to content
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
Diff view
Diff view
28 changes: 1 addition & 27 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ from numpy._core._ufunc_config import (
getbufsize,
seterrcall,
geterrcall,
_ErrKind,
_ErrCall,
errstate,
)

from numpy._core.arrayprint import (
Expand Down Expand Up @@ -757,8 +756,6 @@ _T_contra = TypeVar("_T_contra", contravariant=True)
_RealT_co = TypeVar("_RealT_co", covariant=True)
_ImagT_co = TypeVar("_ImagT_co", covariant=True)

_CallableT = TypeVar("_CallableT", bound=Callable[..., object])

_DTypeT = TypeVar("_DTypeT", bound=dtype)
_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype, default=dtype, covariant=True)
_FlexDTypeT = TypeVar("_FlexDTypeT", bound=dtype[flexible])
Expand Down Expand Up @@ -5735,29 +5732,6 @@ permute_dims = transpose
pow = power
true_divide = divide

class errstate:
__slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under"

def __init__(
self,
*,
call: _ErrCall = ...,
all: _ErrKind | None = None,
divide: _ErrKind | None = None,
over: _ErrKind | None = None,
under: _ErrKind | None = None,
invalid: _ErrKind | None = None,
) -> None: ...
def __enter__(self) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
/,
) -> None: ...
def __call__(self, func: _CallableT) -> _CallableT: ...

# TODO: The type of each `__next__` and `iters` return-type depends
# on the length and dtype of `args`; we can't describe this behavior yet
# as we lack variadics (PEP 646).
Expand Down
50 changes: 44 additions & 6 deletions numpy/_core/_ufunc_config.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from _typeshed import SupportsWrite
from collections.abc import Callable
from typing import Any, Literal, TypeAlias, TypedDict, type_check_only
from types import TracebackType
from typing import Any, Final, Literal, TypeAlias, TypedDict, TypeVar, type_check_only

from numpy import errstate as errstate
__all__ = [
"seterr",
"geterr",
"setbufsize",
"getbufsize",
"seterrcall",
"geterrcall",
"errstate",
]

_ErrKind: TypeAlias = Literal["ignore", "warn", "raise", "call", "print", "log"]
_ErrFunc: TypeAlias = Callable[[str, int], Any]
_ErrCall: TypeAlias = _ErrFunc | SupportsWrite[str]
_ErrCall: TypeAlias = Callable[[str, int], Any] | SupportsWrite[str]

_CallableT = TypeVar("_CallableT", bound=Callable[..., object])

@type_check_only
class _ErrDict(TypedDict):
Expand All @@ -15,6 +25,36 @@ class _ErrDict(TypedDict):
under: _ErrKind
invalid: _ErrKind

###

class _unspecified: ...

_Unspecified: Final[_unspecified]

class errstate:
__slots__ = "_all", "_call", "_divide", "_invalid", "_over", "_token", "_under"

def __init__(
self,
/,
*,
call: _ErrCall | _unspecified = ..., # = _Unspecified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I guess I didn't want to clean that up last time around, but we should just use np._NoValue it seems to me...
Anyway, doesn't matter for this.

(I don't really think this should be backported -- I can say that once every few months, right? :).)

all: _ErrKind | None = None,
divide: _ErrKind | None = None,
over: _ErrKind | None = None,
under: _ErrKind | None = None,
invalid: _ErrKind | None = None,
) -> None: ...
def __call__(self, /, func: _CallableT) -> _CallableT: ...
def __enter__(self) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
/,
) -> None: ...

def seterr(
all: _ErrKind | None = None,
divide: _ErrKind | None = None,
Expand All @@ -27,5 +67,3 @@ def setbufsize(size: int) -> int: ...
def getbufsize() -> int: ...
def seterrcall(func: _ErrCall | None) -> _ErrCall | None: ...
def geterrcall() -> _ErrCall | None: ...

# See `numpy/__init__.pyi` for the `errstate` class and `no_nep5_warnings`
Loading