Skip to content

Commit 5ea0d1f

Browse files
committed
🎨 _typing: replace inline truthy/falsy literals
1 parent a9a79f4 commit 5ea0d1f

File tree

20 files changed

+128
-105
lines changed

20 files changed

+128
-105
lines changed

‎scipy-stubs/_lib/_elementwise_iterative_method.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from collections.abc import Callable, Iterable, Mapping, Sequence
22
from types import ModuleType
3-
from typing import Any, Concatenate, Final, Literal, TypeAlias
3+
from typing import Any, Concatenate, Final, TypeAlias
44
from typing_extensions import TypeVar
55

66
import numpy as np
77
import optype as op
88
import optype.numpy as onp
9+
from scipy._typing import Falsy
910
from ._util import _RichResult
1011

1112
###
@@ -35,7 +36,7 @@ def _initialize(
3536
func: _FuncRealT,
3637
xs: Sequence[onp.ToFloat1D],
3738
args: tuple[onp.ToFloat1D, ...],
38-
complex_ok: Literal[False] = False,
39+
complex_ok: Falsy = False,
3940
preserve_shape: bool | None = None,
4041
xp: _ModuleT | None = None,
4142
) -> tuple[

‎scipy-stubs/cluster/hierarchy.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import numpy as np
77
import optype.numpy as onp
88
import optype.typing as opt
99
from scipy._lib._disjoint_set import DisjointSet
10+
from scipy._typing import Falsy, Truthy
1011
from scipy.spatial.distance import _Metric
1112

1213
__all__ = [
@@ -141,9 +142,9 @@ def cut_tree(
141142

142143
#
143144
@overload
144-
def to_tree(Z: onp.ToArray2D, rd: Literal[False] = False) -> ClusterNode: ...
145+
def to_tree(Z: onp.ToArray2D, rd: Falsy = False) -> ClusterNode: ...
145146
@overload
146-
def to_tree(Z: onp.ToArray2D, rd: Literal[True]) -> tuple[ClusterNode, list[ClusterNode]]: ...
147+
def to_tree(Z: onp.ToArray2D, rd: Truthy) -> tuple[ClusterNode, list[ClusterNode]]: ...
147148

148149
#
149150
def optimal_leaf_ordering(Z: onp.ToArray2D, y: onp.ToArrayND, metric: _Metric = "euclidean") -> _LinkageArray: ...

‎scipy-stubs/integrate/_bvp.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ from typing_extensions import TypeVar
44

55
import numpy as np
66
import optype.numpy as onp
7+
from scipy._typing import Falsy, Truthy
78
from scipy.interpolate import PPoly
89
from scipy.sparse import csc_matrix
910

11+
###
12+
1013
_SCT_fc = TypeVar("_SCT_fc", bound=np.inexact[Any], default=np.float64 | np.complex128)
1114

1215
_FunRHS: TypeAlias = Callable[[onp.Array1D, onp.Array2D[_SCT_fc]], onp.ArrayND[_SCT_fc]]
@@ -225,7 +228,7 @@ def wrap_functions(
225228
bc: _FunBCR[_SCT_fc],
226229
fun_jac: _FunRHS_jac[_SCT_fc] | None,
227230
bc_jac: _FunBCR_jac[_SCT_fc] | None,
228-
k: Literal[False, 0],
231+
k: Falsy,
229232
a: onp.ToFloat,
230233
S: onp.Array2D[np.float64] | None,
231234
D: onp.Array2D[np.float64] | None,
@@ -237,7 +240,7 @@ def wrap_functions(
237240
bc: _FunBCR_p[_SCT_fc],
238241
fun_jac: _FunRHS_jac_p[_SCT_fc] | None,
239242
bc_jac: _FunBCR_jac_p[_SCT_fc] | None,
240-
k: Literal[True, 1],
243+
k: Truthy,
241244
a: onp.ToFloat,
242245
S: onp.Array2D[np.float64] | None,
243246
D: onp.Array2D[np.float64] | None,

‎scipy-stubs/integrate/_ivp/base.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload
33

44
import numpy as np
55
import optype.numpy as onp
6+
from scipy._typing import Truthy
67

78
_VT = TypeVar("_VT", bound=onp.ArrayND[np.inexact[Any]], default=onp.ArrayND[np.inexact[Any]])
89

@@ -32,7 +33,7 @@ class OdeSolver:
3233
y0: onp.ToFloatND,
3334
t_bound: onp.ToFloat,
3435
vectorized: bool,
35-
support_complex: bool = False,
36+
support_complex: onp.ToBool = False,
3637
) -> None: ...
3738
@overload
3839
def __init__(
@@ -43,7 +44,7 @@ class OdeSolver:
4344
y0: onp.ToComplexND,
4445
t_bound: onp.ToFloat,
4546
vectorized: bool,
46-
support_complex: Literal[True],
47+
support_complex: Truthy,
4748
) -> None: ...
4849
@property
4950
def step_size(self, /) -> float | None: ...

‎scipy-stubs/integrate/_ivp/ivp.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from typing_extensions import TypedDict, TypeVar, Unpack
55
import numpy as np
66
import optype.numpy as onp
77
from scipy._lib._util import _RichResult
8+
from scipy._typing import Falsy, Truthy
89
from scipy.sparse import sparray, spmatrix
910
from .base import DenseOutput, OdeSolver
1011
from .common import OdeSolution
@@ -78,7 +79,7 @@ def solve_ivp(
7879
t_eval: onp.ToFloat1D | None = None,
7980
dense_output: bool = False,
8081
events: _Events[_SCT_cf] | None = None,
81-
vectorized: Literal[False, 0] = False,
82+
vectorized: Falsy = False,
8283
args: tuple[object, ...] | None = None,
8384
**options: Unpack[_SolverOptions],
8485
) -> OdeResult[_SCT_cf]: ...
@@ -92,7 +93,7 @@ def solve_ivp(
9293
dense_output: bool = False,
9394
events: _Events[_SCT_cf] | None = None,
9495
*,
95-
vectorized: Literal[True, 1],
96+
vectorized: Truthy,
9697
args: tuple[object, ...] | None = None,
9798
**options: Unpack[_SolverOptions],
9899
) -> OdeResult[_SCT_cf]: ...

‎scipy-stubs/integrate/_odepack_py.pyi

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from typing_extensions import TypeVar, TypeVarTuple, Unpack
33

44
import numpy as np
55
import optype.numpy as onp
6+
from scipy._typing import Falsy, Truthy
67
from ._typing import ODEInfoDict
78

89
__all__ = ["ODEintWarning", "odeint"]
@@ -31,7 +32,7 @@ def odeint(
3132
args: tuple[()] = (),
3233
Dfun: _ODEFunc[_YT] | None = None,
3334
col_deriv: Literal[0, 1] | bool = 0,
34-
full_output: Literal[False, 0] = 0,
35+
full_output: Falsy = 0,
3536
ml: int | None = None,
3637
mu: int | None = None,
3738
rtol: float | None = None,
@@ -46,7 +47,7 @@ def odeint(
4647
mxordn: int = 12,
4748
mxords: int = 5,
4849
printmessg: Literal[0, 1] | bool = 0,
49-
tfirst: Literal[False, 0] = False,
50+
tfirst: Falsy = False,
5051
) -> onp.Array2D[np.floating[Any]]: ...
5152
@overload
5253
def odeint(
@@ -56,7 +57,7 @@ def odeint(
5657
args: tuple[()] = (),
5758
Dfun: _ODEFunc[_YT] | None = None,
5859
col_deriv: Literal[0, 1] | bool = 0,
59-
full_output: Literal[False, 0] = 0,
60+
full_output: Falsy = 0,
6061
ml: int | None = None,
6162
mu: int | None = None,
6263
rtol: float | None = None,
@@ -72,7 +73,7 @@ def odeint(
7273
mxords: int = 5,
7374
printmessg: Literal[0, 1] | bool = 0,
7475
*,
75-
tfirst: Literal[True, 1],
76+
tfirst: Truthy,
7677
) -> onp.Array2D[np.floating[Any]]: ...
7778
@overload
7879
def odeint(
@@ -83,7 +84,7 @@ def odeint(
8384
Dfun: _ODEFunc[_YT] | None = None,
8485
col_deriv: Literal[0, 1] | bool = 0,
8586
*,
86-
full_output: Literal[True, 1],
87+
full_output: Truthy,
8788
ml: int | None = None,
8889
mu: int | None = None,
8990
rtol: float | None = None,
@@ -98,7 +99,7 @@ def odeint(
9899
mxordn: int = 12,
99100
mxords: int = 5,
100101
printmessg: Literal[0, 1] | bool = 0,
101-
tfirst: Literal[False, 0] = False,
102+
tfirst: Falsy = False,
102103
) -> tuple[onp.Array2D[np.floating[Any]], ODEInfoDict]: ...
103104
@overload
104105
def odeint(
@@ -109,7 +110,7 @@ def odeint(
109110
Dfun: _ODEFunc[_YT] | None = None,
110111
col_deriv: Literal[0, 1] | bool = 0,
111112
*,
112-
full_output: Literal[True, 1],
113+
full_output: Truthy,
113114
ml: int | None = None,
114115
mu: int | None = None,
115116
rtol: float | None = None,
@@ -124,7 +125,7 @@ def odeint(
124125
mxordn: int = 12,
125126
mxords: int = 5,
126127
printmessg: Literal[0, 1] | bool = 0,
127-
tfirst: Literal[True, 1],
128+
tfirst: Truthy,
128129
) -> tuple[onp.Array2D[np.floating[Any]], ODEInfoDict]: ...
129130

130131
# specified args
@@ -136,7 +137,7 @@ def odeint(
136137
args: tuple[Unpack[_Ts]] = ...,
137138
Dfun: _ODEFunc[_YT, Unpack[_Ts]] | None = None,
138139
col_deriv: Literal[0, 1] | bool = 0,
139-
full_output: Literal[False, 0] = 0,
140+
full_output: Falsy = 0,
140141
ml: int | None = None,
141142
mu: int | None = None,
142143
rtol: float | None = None,
@@ -151,7 +152,7 @@ def odeint(
151152
mxordn: int = 12,
152153
mxords: int = 5,
153154
printmessg: Literal[0, 1] | bool = 0,
154-
tfirst: Literal[False, 0] = False,
155+
tfirst: Falsy = False,
155156
) -> onp.Array2D[np.floating[Any]]: ...
156157
@overload
157158
def odeint(
@@ -161,7 +162,7 @@ def odeint(
161162
args: tuple[Unpack[_Ts]] = ...,
162163
Dfun: _ODEFuncInv[_YT, Unpack[_Ts]] | None = None,
163164
col_deriv: Literal[0, 1] | bool = 0,
164-
full_output: Literal[False, 0] = 0,
165+
full_output: Falsy = 0,
165166
ml: int | None = None,
166167
mu: int | None = None,
167168
rtol: float | None = None,
@@ -177,7 +178,7 @@ def odeint(
177178
mxords: int = 5,
178179
printmessg: Literal[0, 1] | bool = 0,
179180
*,
180-
tfirst: Literal[True, 1],
181+
tfirst: Truthy,
181182
) -> onp.Array2D[np.floating[Any]]: ...
182183
@overload
183184
def odeint(
@@ -188,7 +189,7 @@ def odeint(
188189
Dfun: _ODEFunc[_YT, Unpack[_Ts]] | None = None,
189190
col_deriv: Literal[0, 1] | bool = 0,
190191
*,
191-
full_output: Literal[True, 1],
192+
full_output: Truthy,
192193
ml: int | None = None,
193194
mu: int | None = None,
194195
rtol: float | None = None,
@@ -203,7 +204,7 @@ def odeint(
203204
mxordn: int = 12,
204205
mxords: int = 5,
205206
printmessg: Literal[0, 1] | bool = 0,
206-
tfirst: Literal[False, 0] = False,
207+
tfirst: Falsy = False,
207208
) -> tuple[onp.Array2D[np.floating[Any]], ODEInfoDict]: ...
208209
@overload
209210
def odeint(
@@ -214,7 +215,7 @@ def odeint(
214215
Dfun: _ODEFuncInv[_YT, Unpack[_Ts]] | None = None,
215216
col_deriv: Literal[0, 1] | bool = 0,
216217
*,
217-
full_output: Literal[True, 1],
218+
full_output: Truthy,
218219
ml: int | None = None,
219220
mu: int | None = None,
220221
rtol: float | None = None,
@@ -229,5 +230,5 @@ def odeint(
229230
mxordn: int = 12,
230231
mxords: int = 5,
231232
printmessg: Literal[0, 1] | bool = 0,
232-
tfirst: Literal[True, 1],
233+
tfirst: Truthy,
233234
) -> tuple[onp.Array2D[np.floating[Any]], ODEInfoDict]: ...

‎scipy-stubs/linalg/_expm_frechet.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from typing import Literal, TypeAlias, overload
22

33
import numpy as np
44
import optype.numpy as onp
5+
from scipy._typing import Falsy, Truthy
56

67
__all__ = ["expm_cond", "expm_frechet"]
78

@@ -16,15 +17,15 @@ def expm_frechet(
1617
A: onp.ToComplex2D,
1718
E: onp.ToComplex2D,
1819
method: _Method | None = None,
19-
compute_expm: Literal[True] = True,
20+
compute_expm: Truthy = True,
2021
check_finite: bool = True,
2122
) -> tuple[_Float2D, _Float2D] | tuple[_Float2D | _Complex2D, _Complex2D]: ...
2223
@overload
2324
def expm_frechet(
2425
A: onp.ToComplex2D,
2526
E: onp.ToComplex2D,
2627
method: _Method | None,
27-
compute_expm: Literal[False],
28+
compute_expm: Falsy,
2829
check_finite: bool = True,
2930
) -> tuple[_Float2D, _Float2D] | tuple[_Float2D | _Complex2D, _Complex2D]: ...
3031
@overload
@@ -33,7 +34,7 @@ def expm_frechet(
3334
E: onp.ToComplex2D,
3435
method: _Method | None = None,
3536
*,
36-
compute_expm: Literal[False],
37+
compute_expm: Falsy,
3738
check_finite: bool = True,
3839
) -> tuple[_Float2D, _Float2D] | tuple[_Float2D | _Complex2D, _Complex2D]: ...
3940

‎scipy-stubs/odr/_odrpack.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from typing import Any, Concatenate, Final, Literal, TypeAlias, TypedDict, overl
33

44
import numpy as np
55
import optype.numpy as onp
6-
from scipy._typing import AnyBool
6+
from scipy._typing import AnyBool, Falsy, Truthy
77

88
__all__ = ["ODR", "Data", "Model", "OdrError", "OdrStop", "OdrWarning", "Output", "RealData", "odr", "odr_error", "odr_stop"]
99

@@ -300,7 +300,7 @@ def odr(
300300
scld: onp.ToFloatND | None = None,
301301
work: onp.ArrayND[np.float64] | None = None,
302302
iwork: onp.ArrayND[np.int32 | np.int64] | None = None,
303-
full_output: Literal[False, 0] = 0,
303+
full_output: Falsy = 0,
304304
) -> tuple[_Float1D, _Float1D, _Float2D]: ...
305305
@overload
306306
def odr(
@@ -331,5 +331,5 @@ def odr(
331331
work: onp.ArrayND[np.float64] | None = None,
332332
iwork: onp.ArrayND[np.int32 | np.int64] | None = None,
333333
*,
334-
full_output: Literal[True, 1],
334+
full_output: Truthy,
335335
) -> tuple[_Float1D, _Float1D, _Float2D, _FullOutput]: ...

‎scipy-stubs/optimize/_numdiff.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from typing import Concatenate, Literal, TypeAlias, overload
33

44
import numpy as np
55
import optype.numpy as onp
6+
from scipy._typing import Falsy, Truthy
67
from scipy.sparse import csr_matrix, sparray, spmatrix
78
from scipy.sparse.linalg import LinearOperator
89

@@ -34,7 +35,7 @@ def approx_derivative(
3435
f0: _ToFloatOr1D | None = None,
3536
bounds: tuple[_ToFloatOr1D, _ToFloatOr1D] = ...,
3637
sparsity: None = None,
37-
as_linear_operator: Literal[False, 0] = False,
38+
as_linear_operator: Falsy = False,
3839
args: tuple[object, ...] = (),
3940
kwargs: Mapping[str, object] | None = None,
4041
) -> _Float1D | onp.Array2D[np.float64]: ...
@@ -49,7 +50,7 @@ def approx_derivative(
4950
bounds: tuple[_ToFloatOr1D, _ToFloatOr1D] = ...,
5051
*,
5152
sparsity: _Sparsity,
52-
as_linear_operator: Literal[False, 0] = False,
53+
as_linear_operator: Falsy = False,
5354
args: tuple[object, ...] = (),
5455
kwargs: Mapping[str, object] | None = None,
5556
) -> csr_matrix: ...
@@ -64,7 +65,7 @@ def approx_derivative(
6465
bounds: tuple[_ToFloatOr1D, _ToFloatOr1D] = ...,
6566
sparsity: _Sparsity | None = None,
6667
*,
67-
as_linear_operator: Literal[True, 1],
68+
as_linear_operator: Truthy,
6869
args: tuple[object, ...] = (),
6970
kwargs: Mapping[str, object] | None = None,
7071
) -> LinearOperator: ...

0 commit comments

Comments
 (0)