Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
TYP: minor fixes related to errstate (#29914)
  • Loading branch information
jorenham authored and charris committed Oct 10, 2025
commit 9c9aee2a11527e8f01fdfbc8c35b6414e7f635de
28 changes: 1 addition & 27 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ from numpy._core._ufunc_config import (
getbufsize,
seterrcall,
geterrcall,
_ErrKind,
_ErrCall,
errstate,
)

from numpy._core.arrayprint import (
Expand Down Expand Up @@ -756,8 +755,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 @@ -5662,29 +5659,6 @@ bitwise_right_shift = right_shift
permute_dims = transpose
pow = power

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

def __init__(
self,
*,
call: _ErrCall = ...,
all: _ErrKind | None = ...,
divide: _ErrKind | None = ...,
over: _ErrKind | None = ...,
under: _ErrKind | None = ...,
invalid: _ErrKind | 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
52 changes: 44 additions & 8 deletions numpy/_core/_ufunc_config.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from collections.abc import Callable
Comment thread
jorenham marked this conversation as resolved.
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 _typeshed import SupportsWrite

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 @@ -16,6 +24,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
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 = ...,
divide: _ErrKind | None = ...,
Expand All @@ -28,5 +66,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