Skip to content
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

Fix typing for commonly used callables #253

Merged
merged 3 commits into from
Sep 26, 2024
Merged
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: 2 additions & 2 deletions src/hamcrest/core/core/isinstanceof.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type
from typing import Type, Any

from hamcrest.core.base_matcher import BaseMatcher
from hamcrest.core.description import Description
Expand All @@ -23,7 +23,7 @@ def describe_to(self, description: Description) -> None:
description.append_text("an instance of ").append_text(self.expected_type.__name__)


def instance_of(atype: Type) -> Matcher[object]:
def instance_of(atype: Type[Any]) -> Matcher[object]:
"""Matches if object is an instance of, or inherits from, a given type.

:param atype: The type to compare against as the expected type.
Expand Down
6 changes: 4 additions & 2 deletions src/hamcrest/core/core/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def describe_match(self, item, match_description: Description) -> None:
)


def raises(exception: Type[Exception], pattern=None, matching=None) -> Matcher[Callable[..., Any]]:
def raises(
exception: Type[Exception], pattern: Optional[str] = None, matching: Optional[Matcher] = None
) -> Matcher[Callable[..., Any]]:
"""Matches if the called function raised the expected exception.

:param exception: The class of the expected exception
Expand Down Expand Up @@ -121,7 +123,7 @@ def __init__(self, func: Callable[..., Any]):
def __call__(self):
self.func(*self.args, **self.kwargs)

def with_args(self, *args, **kwargs):
def with_args(self, *args: Any, **kwargs: Any):
self.args = args
self.kwargs = kwargs
return self
Expand Down