@@ -4,7 +4,9 @@ from types import NotImplementedType
44from typing import Any , ClassVar , Final , Generic , Literal , Protocol , TypeAlias , TypedDict , final , overload , type_check_only
55from typing_extensions import ParamSpec , TypeVar , Unpack
66
7- from scipy ._typing import AnyBool , EnterNoneMixin
7+ import optype .numpy as onp
8+
9+ from scipy ._typing import ExitMixin
810
911__all__ = [
1012 "BackendNotImplementedError" ,
@@ -71,12 +73,14 @@ ArgumentReplacerType: TypeAlias = Callable[
7173class _BackendState : ...
7274
7375@final
74- class _SetBackendContext (EnterNoneMixin ):
76+ class _SetBackendContext (ExitMixin ):
7577 def __init__ (self , / , * args : object , ** kwargs : object ) -> None : ...
78+ def __enter__ (self , / ) -> None : ...
7679
7780@final
78- class _SkipBackendContext (EnterNoneMixin ):
81+ class _SkipBackendContext (ExitMixin ):
7982 def __init__ (self , / , * args : object , ** kwargs : object ) -> None : ...
83+ def __enter__ (self , / ) -> None : ...
8084
8185@final
8286class _Function (Generic [_Tss , _T_co ]):
@@ -96,7 +100,7 @@ class Dispatchable(Generic[_T_co]):
96100 type : _DispatchType [_T_co ]
97101 coercible : Final [bool ]
98102
99- def __init__ (self , / , value : _T_co , dispatch_type : _DispatchType [_T_co ], coercible : AnyBool = True ) -> None : ...
103+ def __init__ (self , / , value : _T_co , dispatch_type : _DispatchType [_T_co ], coercible : onp . ToBool = True ) -> None : ...
100104 @overload
101105 def __getitem__ (self , index : Literal [1 , - 1 ], / ) -> _T_co : ...
102106 @overload
@@ -124,15 +128,15 @@ def generate_multimethod(
124128) -> _Function [_Tss , _T ]: ...
125129
126130#
127- def set_backend (backend : _Backend , coerce : AnyBool = False , only : AnyBool = False ) -> _SetBackendContext : ...
131+ def set_backend (backend : _Backend , coerce : onp . ToBool = False , only : onp . ToBool = False ) -> _SetBackendContext : ...
128132def skip_backend (backend : _Backend ) -> _SkipBackendContext : ...
129133
130134#
131135def set_global_backend (
132- backend : _Backend , coerce : AnyBool = False , only : AnyBool = False , * , try_last : AnyBool = False
136+ backend : _Backend , coerce : onp . ToBool = False , only : onp . ToBool = False , * , try_last : onp . ToBool = False
133137) -> None : ...
134138def register_backend (backend : _Backend ) -> None : ...
135- def clear_backends (domain : str | None , registered : AnyBool = True , globals : AnyBool = False ) -> None : ...
139+ def clear_backends (domain : str | None , registered : onp . ToBool = True , globals : onp . ToBool = False ) -> None : ...
136140
137141#
138142def mark_as (dispatch_type : type [_T ] | str ) -> Callable [[_T ], Dispatchable [_T ]]: ...
@@ -144,37 +148,37 @@ def all_of_type(
144148@overload
145149def wrap_single_convertor (
146150 convert_single : Callable [[_V , _DispatchType [_V ], bool ], _C ],
147- ) -> Callable [[Iterable [Dispatchable [_V ]], AnyBool ], list [_C ]]: ...
151+ ) -> Callable [[Iterable [Dispatchable [_V ]], onp . ToBool ], list [_C ]]: ...
148152@overload
149153def wrap_single_convertor (
150154 convert_single : Callable [[_V , _DispatchType [_V ], bool ], NotImplementedType ],
151- ) -> Callable [[Iterable [Dispatchable [_V ]], AnyBool ], NotImplementedType ]: ...
155+ ) -> Callable [[Iterable [Dispatchable [_V ]], onp . ToBool ], NotImplementedType ]: ...
152156@overload
153157def wrap_single_convertor (
154158 convert_single : Callable [[_V , _DispatchType [_V ], bool ], _C | NotImplementedType ],
155- ) -> Callable [[Iterable [Dispatchable [_V ]], AnyBool ], list [_C ] | NotImplementedType ]: ...
159+ ) -> Callable [[Iterable [Dispatchable [_V ]], onp . ToBool ], list [_C ] | NotImplementedType ]: ...
156160@overload
157161def wrap_single_convertor_instance (
158162 convert_single : Callable [[_S , _V , _DispatchType [_V ], bool ], _C ],
159- ) -> Callable [[_S , Iterable [Dispatchable [_V ]], AnyBool ], list [_C ]]: ...
163+ ) -> Callable [[_S , Iterable [Dispatchable [_V ]], onp . ToBool ], list [_C ]]: ...
160164@overload
161165def wrap_single_convertor_instance (
162166 convert_single : Callable [[_S , _V , _DispatchType [_V ], bool ], NotImplementedType ],
163- ) -> Callable [[_S , Iterable [Dispatchable [_V ]], AnyBool ], NotImplementedType ]: ...
167+ ) -> Callable [[_S , Iterable [Dispatchable [_V ]], onp . ToBool ], NotImplementedType ]: ...
164168@overload
165169def wrap_single_convertor_instance (
166170 convert_single : Callable [[_S , _V , _DispatchType [_V ], bool ], _C | NotImplementedType ],
167- ) -> Callable [[_S , Iterable [Dispatchable [_V ]], AnyBool ], list [_C ] | NotImplementedType ]: ...
171+ ) -> Callable [[_S , Iterable [Dispatchable [_V ]], onp . ToBool ], list [_C ] | NotImplementedType ]: ...
168172
169173#
170174def determine_backend (
171- value : _V , dispatch_type : _DispatchType [_V ], * , domain : str , only : AnyBool = True , coerce : AnyBool = False
175+ value : _V , dispatch_type : _DispatchType [_V ], * , domain : str , only : onp . ToBool = True , coerce : onp . ToBool = False
172176) -> _SetBackendContext : ...
173177def determine_backend_multi (
174178 dispatchables : Iterable [_V | Dispatchable [_V ]],
175179 * ,
176180 domain : str ,
177- only : AnyBool = True ,
178- coerce : AnyBool = False ,
181+ only : onp . ToBool = True ,
182+ coerce : onp . ToBool = False ,
179183 ** kwargs : Unpack [_DetermineBackendMultiKwargs [_T ]],
180184) -> _SetBackendContext : ...
0 commit comments