From d7fd16551a095a751ef493f105beecc9179b0341 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 02:58:39 -0500 Subject: [PATCH 1/2] Add comment explaining NonCallableMock Any subclassing --- stdlib/unittest/mock.pyi | 5 ++++- stubs/mock/mock/mock.pyi | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 47535499a9f2..9f2bbc6711c5 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -102,7 +102,10 @@ class _CallList(list[_Call]): class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... -class NonCallableMock(Base, Any): +# Defining this and other mock classes exactly like the source causes +# many false positives with mypy and production code. +# We improve by use a class with an "Any" base class. +class NonCallableMock(Base, Any): # type: ignore[misc] def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ... def __init__( self, diff --git a/stubs/mock/mock/mock.pyi b/stubs/mock/mock/mock.pyi index 6e52136ce660..df549960ebb2 100644 --- a/stubs/mock/mock/mock.pyi +++ b/stubs/mock/mock/mock.pyi @@ -76,7 +76,10 @@ class _CallList(list[_Call]): class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... -class NonCallableMock(Base, Any): +# Defining this and other mock classes exactly like the source causes +# many false positives with mypy and production code. +# We improve by use a class with an "Any" base class. +class NonCallableMock(Base, Any): # type: ignore[misc] def __new__( cls: type[Self], spec: list[str] | object | type[object] | None = ..., From 85f73613034e0103042a7ea2d313b24745af3b24 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 11 Jan 2023 03:03:48 -0500 Subject: [PATCH 2/2] reword --- stdlib/unittest/mock.pyi | 5 ++--- stubs/mock/mock/mock.pyi | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 9f2bbc6711c5..3256461df907 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -102,9 +102,8 @@ class _CallList(list[_Call]): class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... -# Defining this and other mock classes exactly like the source causes -# many false positives with mypy and production code. -# We improve by use a class with an "Any" base class. +# We subclass with "Any" because defining this and other mock classes exactly like the source +# causes many false positives with mypy and production code. class NonCallableMock(Base, Any): # type: ignore[misc] def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ... def __init__( diff --git a/stubs/mock/mock/mock.pyi b/stubs/mock/mock/mock.pyi index df549960ebb2..9c6e8dc2fac0 100644 --- a/stubs/mock/mock/mock.pyi +++ b/stubs/mock/mock/mock.pyi @@ -76,9 +76,8 @@ class _CallList(list[_Call]): class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... -# Defining this and other mock classes exactly like the source causes -# many false positives with mypy and production code. -# We improve by use a class with an "Any" base class. +# We subclass with "Any" because defining this and other mock classes exactly like the source +# causes many false positives with mypy and production code. class NonCallableMock(Base, Any): # type: ignore[misc] def __new__( cls: type[Self],