Skip to content

[BF] #52 Fix rest_method type hints #53

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions src/dataclass_rest/rest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from typing import Any, Callable, Dict, Optional, TypeVar, cast
from typing import Any, Callable, Dict, Optional, Protocol, cast

from .boundmethod import BoundMethod
from .method import Method
from .parse_func import DEFAULT_BODY_PARAM, UrlTemplate, parse_func

_Func = TypeVar("_Func", bound=Callable[..., Any])

class RestWrapper(Protocol):
def __call__(
self,
url_template: UrlTemplate,
*,
body_name: str = DEFAULT_BODY_PARAM,
additional_params: Optional[Dict[str, Any]] = None,
method_class: Optional[Callable[..., BoundMethod]] = None,
send_json: bool = True,
) -> Callable[[Callable], Method]:
raise NotImplementedError


def rest(
Expand Down Expand Up @@ -33,11 +44,11 @@ def dec(func: Callable) -> Method:
return dec


def _rest_method(func: _Func, method: str) -> _Func:
def _rest_method(func: Callable[..., Any], method: str) -> RestWrapper:
def wrapper(*args, **kwargs):
return func(*args, **kwargs, method=method)

return cast(_Func, wrapper)
return cast(RestWrapper, wrapper)


get = _rest_method(rest, method="GET")
Expand Down