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 <Alex.Waygood@Gmail.com>
This commit is contained in:
Nikita Sobolev
2023-09-02 17:03:39 +03:00
committed by GitHub
parent 454438e4db
commit f0ba5ba2a2
3 changed files with 21 additions and 4 deletions

View File

@@ -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,