Skip to content

Commit 74a8900

Browse files
authored
mock: fix overloads (#5534)
* mock: fix overloads Fixes #5533. This changes the order and in some cases removes default values from new. * ignore incompatible overlaps Co-authored-by: hauntsaninja <>
1 parent af33b09 commit 74a8900

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

stdlib/unittest/mock.pyi

+23-23
Original file line numberDiff line numberDiff line change
@@ -204,112 +204,112 @@ class _patcher:
204204
TEST_PREFIX: str
205205
dict: Type[_patch_dict]
206206
if sys.version_info >= (3, 8):
207+
# This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
208+
# Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
209+
# but that's impossible with the current type system.
207210
@overload
208211
def __call__( # type: ignore
209212
self,
210213
target: Any,
211-
*,
214+
new: _T,
212215
spec: Optional[Any] = ...,
213216
create: bool = ...,
214217
spec_set: Optional[Any] = ...,
215218
autospec: Optional[Any] = ...,
216219
new_callable: Optional[Any] = ...,
217220
**kwargs: Any,
218-
) -> _patch[Union[MagicMock, AsyncMock]]: ...
219-
# This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
220-
# Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
221-
# but that's impossible with the current type system.
221+
) -> _patch[_T]: ...
222222
@overload
223-
def __call__(
223+
def __call__( # type: ignore
224224
self,
225225
target: Any,
226-
new: _T,
226+
*,
227227
spec: Optional[Any] = ...,
228228
create: bool = ...,
229229
spec_set: Optional[Any] = ...,
230230
autospec: Optional[Any] = ...,
231231
new_callable: Optional[Any] = ...,
232232
**kwargs: Any,
233-
) -> _patch[_T]: ...
233+
) -> _patch[Union[MagicMock, AsyncMock]]: ...
234234
else:
235235
@overload
236236
def __call__( # type: ignore
237237
self,
238238
target: Any,
239-
*,
239+
new: _T,
240240
spec: Optional[Any] = ...,
241241
create: bool = ...,
242242
spec_set: Optional[Any] = ...,
243243
autospec: Optional[Any] = ...,
244244
new_callable: Optional[Any] = ...,
245245
**kwargs: Any,
246-
) -> _patch[MagicMock]: ...
246+
) -> _patch[_T]: ...
247247
@overload
248-
def __call__(
248+
def __call__( # type: ignore
249249
self,
250250
target: Any,
251-
new: _T,
251+
*,
252252
spec: Optional[Any] = ...,
253253
create: bool = ...,
254254
spec_set: Optional[Any] = ...,
255255
autospec: Optional[Any] = ...,
256256
new_callable: Optional[Any] = ...,
257257
**kwargs: Any,
258-
) -> _patch[_T]: ...
258+
) -> _patch[MagicMock]: ...
259259
if sys.version_info >= (3, 8):
260260
@overload
261261
def object( # type: ignore
262262
self,
263263
target: Any,
264264
attribute: str,
265-
*,
265+
new: _T,
266266
spec: Optional[Any] = ...,
267267
create: bool = ...,
268268
spec_set: Optional[Any] = ...,
269269
autospec: Optional[Any] = ...,
270270
new_callable: Optional[Any] = ...,
271271
**kwargs: Any,
272-
) -> _patch[Union[MagicMock, AsyncMock]]: ...
272+
) -> _patch[_T]: ...
273273
@overload
274-
def object(
274+
def object( # type: ignore
275275
self,
276276
target: Any,
277277
attribute: str,
278-
new: _T = ...,
278+
*,
279279
spec: Optional[Any] = ...,
280280
create: bool = ...,
281281
spec_set: Optional[Any] = ...,
282282
autospec: Optional[Any] = ...,
283283
new_callable: Optional[Any] = ...,
284284
**kwargs: Any,
285-
) -> _patch[_T]: ...
285+
) -> _patch[Union[MagicMock, AsyncMock]]: ...
286286
else:
287287
@overload
288288
def object( # type: ignore
289289
self,
290290
target: Any,
291291
attribute: str,
292-
*,
292+
new: _T,
293293
spec: Optional[Any] = ...,
294294
create: bool = ...,
295295
spec_set: Optional[Any] = ...,
296296
autospec: Optional[Any] = ...,
297297
new_callable: Optional[Any] = ...,
298298
**kwargs: Any,
299-
) -> _patch[MagicMock]: ...
299+
) -> _patch[_T]: ...
300300
@overload
301-
def object(
301+
def object( # type: ignore
302302
self,
303303
target: Any,
304304
attribute: str,
305-
new: _T = ...,
305+
*,
306306
spec: Optional[Any] = ...,
307307
create: bool = ...,
308308
spec_set: Optional[Any] = ...,
309309
autospec: Optional[Any] = ...,
310310
new_callable: Optional[Any] = ...,
311311
**kwargs: Any,
312-
) -> _patch[_T]: ...
312+
) -> _patch[MagicMock]: ...
313313
def multiple(
314314
self,
315315
target: Any,

0 commit comments

Comments
 (0)