Skip to content

Add comment explaining NonCallableMock's Any subclassing #9496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stdlib/unittest/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class _CallList(list[_Call]):
class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class NonCallableMock(Base, Any):
# 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__(
self,
Expand Down
4 changes: 3 additions & 1 deletion stubs/mock/mock/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class _CallList(list[_Call]):
class Base:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

class NonCallableMock(Base, Any):
# 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],
spec: list[str] | object | type[object] | None = ...,
Expand Down