Skip to content
Open
Changes from 2 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
36 changes: 24 additions & 12 deletions nest/core/decorators/http_method.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from typing import Callable, List, Union, TypeVar, 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 (PostgresSync)
I’ve attached the relevant part of the log for your convenience:
ImportError: cannot import name 'TypeAlias' from 'typing' module in Python 3.9


Finding type: Log Error

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. The commit 9de7fce modified the import statement to handle different Python versions, addressing the ImportError for TypeAlias in Python 3.9. The code now conditionally imports TypeAlias from typing_extensions for versions below 3.10, resolving the issue raised in the thread.

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.

same as above

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 (SyncORM)
I’ve attached the relevant part of the log for your convenience:
ImportError: cannot import name 'TypeAlias' from 'typing' module in Python 3.9


Finding type: Log Error

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

if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec


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

class HTTPMethod(Enum):
GET = "GET"
Expand All @@ -12,20 +22,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 +47,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)