From f0ba5ba2a2814293d6b16f033e8db7e3ff45bf93 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sat, 2 Sep 2023 17:03:39 +0300 Subject: [PATCH] Update `unittest.mock` to 3.12 (#10650) And harmonise some annotations between the stdlib `unittest.mock` module and the third-party `mock` backport package. Co-authored-by: Alex Waygood --- stdlib/unittest/mock.pyi | 20 +++++++++++++++++++- stubs/mock/mock/mock.pyi | 4 ++-- tests/stubtest_allowlists/py312.txt | 1 - 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 66120197b..baf025bde 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -106,7 +106,25 @@ class Base: # We subclass with "Any" because mocks are explicitly designed to stand in for other types, # something that can't be expressed with our static type system. class NonCallableMock(Base, Any): - def __new__(__cls, *args: Any, **kw: Any) -> Self: ... + if sys.version_info >= (3, 12): + def __new__( + cls, + spec: list[str] | object | type[object] | None = None, + wraps: Any | None = None, + name: str | None = None, + spec_set: list[str] | object | type[object] | None = None, + parent: NonCallableMock | None = None, + _spec_state: Any | None = None, + _new_name: str = "", + _new_parent: NonCallableMock | None = None, + _spec_as_instance: bool = False, + _eat_self: bool | None = None, + unsafe: bool = False, + **kwargs: Any, + ) -> Self: ... + else: + def __new__(__cls, *args: Any, **kw: Any) -> Self: ... + def __init__( self, spec: list[str] | object | type[object] | None = None, diff --git a/stubs/mock/mock/mock.pyi b/stubs/mock/mock/mock.pyi index 0479bde4c..04e314e30 100644 --- a/stubs/mock/mock/mock.pyi +++ b/stubs/mock/mock/mock.pyi @@ -89,7 +89,7 @@ class NonCallableMock(Base, Any): def __new__( cls, spec: list[str] | object | type[object] | None = None, - wraps: Incomplete | None = None, + wraps: Any | None = None, name: str | None = None, spec_set: list[str] | object | type[object] | None = None, parent: NonCallableMock | None = None, @@ -104,7 +104,7 @@ class NonCallableMock(Base, Any): def __init__( self, spec: list[str] | object | type[object] | None = None, - wraps: Incomplete | None = None, + wraps: Any | None = None, name: str | None = None, spec_set: list[str] | object | type[object] | None = None, parent: NonCallableMock | None = None, diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index eacc5514f..a46c49cc5 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -32,7 +32,6 @@ typing.override typing_extensions.Protocol typing_extensions.SupportsAbs.__type_params__ typing_extensions.SupportsRound.__type_params__ -unittest.mock.NonCallableMock.__new__ urllib.request.AbstractHTTPHandler.__init__ urllib.request.HTTPSHandler.__init__ zipfile.Path.glob