Skip to content
Open
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
29 changes: 17 additions & 12 deletions nest/core/decorators/http_method.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Callable, List, Union, TypeVar, ParamSpec, TypeAlias

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ Failed check: CLI Test / test (MongoDB)
I’ve attached the relevant part of the log for your convenience:
ImportError: cannot import name 'ParamSpec' from 'typing' module in Python 3.9


Finding type: Log Error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added version check

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks like this comment has been addressed in commit 58d4b04. The code now checks the Python version and imports ParamSpec from typing_extensions for versions below 3.10, resolving the ImportError for Python 3.9.

from enum import Enum
from typing import Any, Callable, List, Union

P = ParamSpec("P")
R = TypeVar("R")
Func: TypeAlias = Callable[[P], R]

class HTTPMethod(Enum):
GET = "GET"
Expand All @@ -12,20 +15,22 @@ class HTTPMethod(Enum):
OPTIONS = "OPTIONS"


def route(http_method: HTTPMethod, route_path: Union[str, List[str]] = "/", **kwargs):
def route(http_method: HTTPMethod, route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[[Func], Func]:
"""
Decorator that defines a route for the controller.

Args:
http_method (HTTPMethod): The HTTP method for the route (GET, POST, DELETE, PUT, PATCH).
route_path (Union[str, List[str]]): The route path for the route. example: "/users"
route_path (Union[str, List[str]]): The route path for the route.
**kwargs: Additional keyword arguments to configure the route.

Returns:
function: The decorated function.
function: The decorated function, preserving the signature.
"""

def decorator(func):
def decorator(func: Func) -> Func:

# Add custom route metadata
func.__http_method__ = http_method
func.__route_path__ = route_path
func.__kwargs__ = kwargs
Expand All @@ -35,29 +40,29 @@ def decorator(func):
return decorator


def Get(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Get(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.GET, route_path, **kwargs)


def Post(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Post(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.POST, route_path, **kwargs)


def Delete(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Delete(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.DELETE, route_path, **kwargs)


def Put(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Put(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.PUT, route_path, **kwargs)


def Patch(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Patch(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.PATCH, route_path, **kwargs)


def Head(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Head(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.HEAD, route_path, **kwargs)


def Options(route_path: Union[str, List[str]] = "/", **kwargs) -> Callable[..., Any]:
def Options(route_path: Union[str, List[str]] = "/", **kwargs):
return route(HTTPMethod.OPTIONS, route_path, **kwargs)