FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make type of `unitest.mock.Any` a subclass of `Any` by donbarbos · Pull Request #14708 · python/typeshed · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .pyi  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 28 additions & 1 deletion stdlib/@tests/test_cases/check_unittest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fractions import Fraction
from typing import TypedDict, Union
from typing_extensions import assert_type
from unittest.mock import AsyncMock, MagicMock, Mock, patch
from unittest.mock import _ANY, ANY, AsyncMock, MagicMock, Mock, patch

case = unittest.TestCase()

Expand Down Expand Up @@ -226,3 +226,30 @@ def obj_f_explicit_new_callable(i: int, new_callable_ret: int) -> str:

with patch.object(Decimal, "exp", new_callable=lambda: 42) as obj_explicit_new_callable_enter:
assert_type(obj_explicit_new_callable_enter, int)


###
# Tests for mock.ANY
###


assert_type(ANY, _ANY) # Make sure ANY has runtime type


# Regression tests. See https://github.com/python/typeshed/issues/14701
class TD(TypedDict):
x: str
y: float


td: TD = {"x": "1", "y": ANY}


def test_as_param(x: str) -> None: ...


test_as_param(ANY)


def test_as_return_value(x: int) -> TD:
return {"x": str(x), "y": ANY}
3 changes: 2 additions & 1 deletion stdlib/unittest/mock.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ class MagicProxy(Base):
def create_mock(self) -> Any: ...
def __get__(self, obj: Any, _type: Any | None = None) -> Any: ...

class _ANY:
# See https://github.com/python/typeshed/issues/14701
class _ANY(Any):
def __eq__(self, other: object) -> Literal[True]: ...
def __ne__(self, other: object) -> Literal[False]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
Expand Down
Loading

Back | FazBrowse Home | New Git URL