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 type hints #37

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions dataclass_rest/rest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from functools import partial
from typing import Any, Dict, Optional, Callable
from typing import Any, Dict, Optional, Callable, ParamSpec, TypeVar

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

_P = ParamSpec("_P")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is 3.10+ only, currently this package support 3.6+

_RT = TypeVar("_RT")


def rest(
url_template: str,
Expand Down Expand Up @@ -32,8 +34,15 @@ def dec(func: Callable) -> Method:
return dec


get = partial(rest, method="GET")
post = partial(rest, method="POST")
put = partial(rest, method="PUT")
patch = partial(rest, method="PATCH")
delete = partial(rest, method="DELETE")
def _rest_method(func: Callable[_P, _RT], method: str) -> Callable[_P, _RT]:
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _RT:
return func(*args, **kwargs, method=method)

return wrapper


get = _rest_method(rest, method="GET")
post = _rest_method(rest, method="POST")
put = _rest_method(rest, method="PUT")
patch = _rest_method(rest, method="PATCH")
delete = _rest_method(rest, method="DELETE")