Skip to content

Commit 48b7f94

Browse files
authored
Merge pull request numpy#26941 from jorenham/distribute-generic-nbit-unions
TYP: Non-distributive ``numpy.generic`` type args.
2 parents c556f8c + 6f74775 commit 48b7f94

File tree

4 files changed

+118
-116
lines changed

4 files changed

+118
-116
lines changed

numpy/_typing/_callable.pyi

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from numpy import (
3535
complexfloating,
3636
complex128,
3737
)
38-
from ._nbit import _NBitInt, _NBitDouble
38+
from ._nbit import _NBitInt
3939
from ._scalars import (
4040
_BoolLike_co,
4141
_IntLike_co,
@@ -121,7 +121,7 @@ class _BoolDivMod(Protocol):
121121
@overload # platform dependent
122122
def __call__(self, other: int, /) -> _2Tuple[int_]: ...
123123
@overload
124-
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
124+
def __call__(self, other: float, /) -> _2Tuple[np.float64]: ...
125125
@overload
126126
def __call__(self, other: _IntType, /) -> _2Tuple[_IntType]: ...
127127
@overload
@@ -139,34 +139,34 @@ class _IntTrueDiv(Protocol[_NBit1]):
139139
@overload
140140
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
141141
@overload
142-
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
142+
def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ...
143143
@overload
144-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
144+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
145145
@overload
146146
def __call__(
147-
self, other: complex, /,
148-
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
147+
self, other: complex, /
148+
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
149149
@overload
150-
def __call__(self, other: integer[_NBit2], /) -> floating[_NBit1 | _NBit2]: ...
150+
def __call__(
151+
self, other: integer[_NBit2], /
152+
) -> floating[_NBit1] | floating[_NBit2]: ...
151153

152154
class _UnsignedIntOp(Protocol[_NBit1]):
153155
# NOTE: `uint64 + signedinteger -> float64`
154156
@overload
155157
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
156158
@overload
157-
def __call__(
158-
self, other: int | signedinteger[Any], /
159-
) -> Any: ...
159+
def __call__(self, other: int | signedinteger[Any], /) -> Any: ...
160160
@overload
161-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
161+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
162162
@overload
163163
def __call__(
164-
self, other: complex, /,
165-
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
164+
self, other: complex, /
165+
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
166166
@overload
167167
def __call__(
168168
self, other: unsignedinteger[_NBit2], /
169-
) -> unsignedinteger[_NBit1 | _NBit2]: ...
169+
) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ...
170170

171171
class _UnsignedIntBitOp(Protocol[_NBit1]):
172172
@overload
@@ -178,135 +178,137 @@ class _UnsignedIntBitOp(Protocol[_NBit1]):
178178
@overload
179179
def __call__(
180180
self, other: unsignedinteger[_NBit2], /
181-
) -> unsignedinteger[_NBit1 | _NBit2]: ...
181+
) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ...
182182

183183
class _UnsignedIntMod(Protocol[_NBit1]):
184184
@overload
185185
def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ...
186186
@overload
187-
def __call__(
188-
self, other: int | signedinteger[Any], /
189-
) -> Any: ...
187+
def __call__(self, other: int | signedinteger[Any], /) -> Any: ...
190188
@overload
191-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
189+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
192190
@overload
193191
def __call__(
194192
self, other: unsignedinteger[_NBit2], /
195-
) -> unsignedinteger[_NBit1 | _NBit2]: ...
193+
) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ...
196194

197195
class _UnsignedIntDivMod(Protocol[_NBit1]):
198196
@overload
199197
def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ...
200198
@overload
201-
def __call__(
202-
self, other: int | signedinteger[Any], /
203-
) -> _2Tuple[Any]: ...
199+
def __call__(self, other: int | signedinteger[Any], /) -> _2Tuple[Any]: ...
204200
@overload
205-
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
201+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ...
206202
@overload
207203
def __call__(
208204
self, other: unsignedinteger[_NBit2], /
209-
) -> _2Tuple[unsignedinteger[_NBit1 | _NBit2]]: ...
205+
) -> _2Tuple[unsignedinteger[_NBit1]] | _2Tuple[unsignedinteger[_NBit2]]: ...
210206

211207
class _SignedIntOp(Protocol[_NBit1]):
212208
@overload
213209
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
214210
@overload
215-
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
211+
def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ...
216212
@overload
217-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
213+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
218214
@overload
219215
def __call__(
220-
self, other: complex, /,
221-
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
216+
self, other: complex, /
217+
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
222218
@overload
223219
def __call__(
224-
self, other: signedinteger[_NBit2], /,
225-
) -> signedinteger[_NBit1 | _NBit2]: ...
220+
self, other: signedinteger[_NBit2], /
221+
) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ...
226222

227223
class _SignedIntBitOp(Protocol[_NBit1]):
228224
@overload
229225
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
230226
@overload
231-
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
227+
def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ...
232228
@overload
233229
def __call__(
234-
self, other: signedinteger[_NBit2], /,
235-
) -> signedinteger[_NBit1 | _NBit2]: ...
230+
self, other: signedinteger[_NBit2], /
231+
) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ...
236232

237233
class _SignedIntMod(Protocol[_NBit1]):
238234
@overload
239235
def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ...
240236
@overload
241-
def __call__(self, other: int, /) -> signedinteger[_NBit1 | _NBitInt]: ...
237+
def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ...
242238
@overload
243-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
239+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
244240
@overload
245241
def __call__(
246-
self, other: signedinteger[_NBit2], /,
247-
) -> signedinteger[_NBit1 | _NBit2]: ...
242+
self, other: signedinteger[_NBit2], /
243+
) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ...
248244

249245
class _SignedIntDivMod(Protocol[_NBit1]):
250246
@overload
251247
def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ...
252248
@overload
253-
def __call__(self, other: int, /) -> _2Tuple[signedinteger[_NBit1 | _NBitInt]]: ...
249+
def __call__(self, other: int, /) -> _2Tuple[signedinteger[_NBit1]] | _2Tuple[int_]: ...
254250
@overload
255-
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
251+
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ...
256252
@overload
257253
def __call__(
258-
self, other: signedinteger[_NBit2], /,
259-
) -> _2Tuple[signedinteger[_NBit1 | _NBit2]]: ...
254+
self, other: signedinteger[_NBit2], /
255+
) -> _2Tuple[signedinteger[_NBit1]] | _2Tuple[signedinteger[_NBit2]]: ...
260256

261257
class _FloatOp(Protocol[_NBit1]):
262258
@overload
263259
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
264260
@overload
265-
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
261+
def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ...
266262
@overload
267-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
263+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
268264
@overload
269265
def __call__(
270-
self, other: complex, /,
271-
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
266+
self, other: complex, /
267+
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
272268
@overload
273269
def __call__(
274270
self, other: integer[_NBit2] | floating[_NBit2], /
275-
) -> floating[_NBit1 | _NBit2]: ...
271+
) -> floating[_NBit1] | floating[_NBit2]: ...
276272

277273
class _FloatMod(Protocol[_NBit1]):
278274
@overload
279275
def __call__(self, other: bool, /) -> floating[_NBit1]: ...
280276
@overload
281-
def __call__(self, other: int, /) -> floating[_NBit1 | _NBitInt]: ...
277+
def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ...
282278
@overload
283-
def __call__(self, other: float, /) -> floating[_NBit1 | _NBitDouble]: ...
279+
def __call__(self, other: float, /) -> floating[_NBit1] | float64: ...
284280
@overload
285281
def __call__(
286282
self, other: integer[_NBit2] | floating[_NBit2], /
287-
) -> floating[_NBit1 | _NBit2]: ...
283+
) -> floating[_NBit1] | floating[_NBit2]: ...
288284

289285
class _FloatDivMod(Protocol[_NBit1]):
290286
@overload
291287
def __call__(self, other: bool, /) -> _2Tuple[floating[_NBit1]]: ...
292288
@overload
293-
def __call__(self, other: int, /) -> _2Tuple[floating[_NBit1 | _NBitInt]]: ...
289+
def __call__(
290+
self, other: int, /
291+
) -> _2Tuple[floating[_NBit1]] | _2Tuple[floating[_NBitInt]]: ...
294292
@overload
295-
def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1 | _NBitDouble]]: ...
293+
def __call__(
294+
self, other: float, /
295+
) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ...
296296
@overload
297297
def __call__(
298298
self, other: integer[_NBit2] | floating[_NBit2], /
299-
) -> _2Tuple[floating[_NBit1 | _NBit2]]: ...
299+
) -> _2Tuple[floating[_NBit1]] | _2Tuple[floating[_NBit2]]: ...
300300

301301
class _ComplexOp(Protocol[_NBit1]):
302302
@overload
303303
def __call__(self, other: bool, /) -> complexfloating[_NBit1, _NBit1]: ...
304304
@overload
305-
def __call__(self, other: int, /) -> complexfloating[_NBit1 | _NBitInt, _NBit1 | _NBitInt]: ...
305+
def __call__(
306+
self, other: int, /
307+
) -> complexfloating[_NBit1, _NBit1] | complexfloating[_NBitInt, _NBitInt]: ...
306308
@overload
307309
def __call__(
308310
self, other: complex, /,
309-
) -> complexfloating[_NBit1 | _NBitDouble, _NBit1 | _NBitDouble]: ...
311+
) -> complexfloating[_NBit1, _NBit1] | complex128: ...
310312
@overload
311313
def __call__(
312314
self,
@@ -315,7 +317,7 @@ class _ComplexOp(Protocol[_NBit1]):
315317
| floating[_NBit2]
316318
| complexfloating[_NBit2, _NBit2]
317319
), /,
318-
) -> complexfloating[_NBit1 | _NBit2, _NBit1 | _NBit2]: ...
320+
) -> complexfloating[_NBit1, _NBit1] | complexfloating[_NBit2, _NBit2]: ...
319321

320322
class _NumberOp(Protocol):
321323
def __call__(self, other: _NumberLike_co, /) -> Any: ...

0 commit comments

Comments
 (0)