From 420346b2c2a5a0eda1c54c5eddd2ba3d3e6af5a2 Mon Sep 17 00:00:00 2001 From: Shannon Zhu Date: Tue, 13 Aug 2019 08:32:23 -0700 Subject: [PATCH 1/2] Update how mock classes alias to Any > First, the z: Any situation looks like a bug or accidental feature to me. This is definitely meant (and works) as a variable declaration; that it also allows using z as a type seems wrong. I can't find any evidence in PEP 484 that this was intended; in mypy it's likely the accidental result of other design choices meant to shut up errors about Any. Ideally these classes could be declared as empty class stubs, but since the comments suggest this isn't possible yet, let's update these to be type aliases to Any rather than global variables of type Any. This would avoid invalid type errors when the implementation of type checkers respect the intention that `z: Any` does not make `z` a valid type. --- third_party/2and3/mock.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/third_party/2and3/mock.pyi b/third_party/2and3/mock.pyi index cb3db6198b41..8b20ea60217d 100644 --- a/third_party/2and3/mock.pyi +++ b/third_party/2and3/mock.pyi @@ -33,14 +33,14 @@ class Base: # TODO: Defining this and other mock classes as classes in this stub causes # many false positives with mypy and production code. See if we can # improve mypy somehow and use a class with an "Any" base class. -NonCallableMock: Any +NonCallableMock = Any class CallableMixin(Base): side_effect: Any def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... -Mock: Any +Mock = Any class _patch: attribute_name: Any @@ -94,8 +94,8 @@ patch: _patcher class MagicMixin: def __init__(self, *args: Any, **kw: Any) -> None: ... -NonCallableMagicMock: Any -MagicMock: Any +NonCallableMagicMock = Any +MagicMock = Any class MagicProxy: name: Any @@ -140,7 +140,7 @@ class _SpecState: def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... -PropertyMock: Any +PropertyMock = Any if sys.version_info >= (3, 7): def seal(mock: Any) -> None: ... From 97a11f7b4f38f2ddf5b80e285ba540d8e0e07baa Mon Sep 17 00:00:00 2001 From: Shannon Zhu Date: Tue, 13 Aug 2019 08:38:18 -0700 Subject: [PATCH 2/2] Update mock.pyi --- stdlib/3/unittest/mock.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index cb3db6198b41..8b20ea60217d 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -33,14 +33,14 @@ class Base: # TODO: Defining this and other mock classes as classes in this stub causes # many false positives with mypy and production code. See if we can # improve mypy somehow and use a class with an "Any" base class. -NonCallableMock: Any +NonCallableMock = Any class CallableMixin(Base): side_effect: Any def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... -Mock: Any +Mock = Any class _patch: attribute_name: Any @@ -94,8 +94,8 @@ patch: _patcher class MagicMixin: def __init__(self, *args: Any, **kw: Any) -> None: ... -NonCallableMagicMock: Any -MagicMock: Any +NonCallableMagicMock = Any +MagicMock = Any class MagicProxy: name: Any @@ -140,7 +140,7 @@ class _SpecState: def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... -PropertyMock: Any +PropertyMock = Any if sys.version_info >= (3, 7): def seal(mock: Any) -> None: ...