From 2454156a0cb6ae34e1a38313c8bb70672dc4bfbc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:51:18 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- integration_tests/subroutes/__init__.py | 1 - integration_tests/subroutes/di_subrouter.py | 1 + integration_tests/test_dependency_injection.py | 1 + robyn/__init__.py | 9 +-------- robyn/dependency_injection.py | 9 +++++---- robyn/robyn.pyi | 3 +++ robyn/router.py | 9 +-------- robyn/ws.py | 4 +--- 8 files changed, 13 insertions(+), 24 deletions(-) diff --git a/integration_tests/subroutes/__init__.py b/integration_tests/subroutes/__init__.py index e569ff8a1..7cfff2d39 100644 --- a/integration_tests/subroutes/__init__.py +++ b/integration_tests/subroutes/__init__.py @@ -1,6 +1,5 @@ from robyn import SubRouter, jsonify, WebSocket -from subroutes.di_subrouter import di_subrouter sub_router = SubRouter(__name__, prefix="/sub_router") diff --git a/integration_tests/subroutes/di_subrouter.py b/integration_tests/subroutes/di_subrouter.py index 6749b4c11..633cdffe8 100644 --- a/integration_tests/subroutes/di_subrouter.py +++ b/integration_tests/subroutes/di_subrouter.py @@ -11,6 +11,7 @@ def sync_subrouter_route_dependency(request, router_dependencies): return router_dependencies["ROUTER_DEPENDENCY"] + @di_subrouter.get("/subrouter_global_di") def sync_subrouter_global_dependency(request, global_dependencies): return global_dependencies["GLOBAL_DEPENDENCY"] diff --git a/integration_tests/test_dependency_injection.py b/integration_tests/test_dependency_injection.py index 012dab2f5..198e763c2 100644 --- a/integration_tests/test_dependency_injection.py +++ b/integration_tests/test_dependency_injection.py @@ -16,6 +16,7 @@ def test_router_dependency_injection(benchmark): assert r.status_code == 200 assert r.text == "ROUTER DEPENDENCY" + @pytest.mark.benchmark def test_subrouter_global_dependency_injection(benchmark): r = get("/di_subrouter/subrouter_global_di") diff --git a/robyn/__init__.py b/robyn/__init__.py index 3608880d2..6a5913136 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -73,14 +73,7 @@ def __init__( self.exception_handler: Optional[Callable] = None self.authentication_handler: Optional[AuthenticationHandler] = None - def add_route( - self, - route_type: Union[HttpMethod, str], - endpoint: str, - handler: Callable, - is_const: bool = False, - auth_required: bool = False - ): + def add_route(self, route_type: Union[HttpMethod, str], endpoint: str, handler: Callable, is_const: bool = False, auth_required: bool = False): """ Connect a URI to a handler diff --git a/robyn/dependency_injection.py b/robyn/dependency_injection.py index 2e396723e..5200f5637 100644 --- a/robyn/dependency_injection.py +++ b/robyn/dependency_injection.py @@ -1,6 +1,7 @@ """ This is Robyn's dependency injection file. """ + class DependencyMap: def __init__(self): #'request' and 'response' mappings are needed for when constructing deps_to_pass in router.py @@ -64,7 +65,7 @@ def merge_dependencies(self, target_router): target_router.dependencies.get_global_dependencies()[dep_key] = self.get_global_dependencies()[dep_key] def get_dependency_map(self, router) -> dict: - return { - "global_dependencies": self.get_global_dependencies(), - "router_dependencies": self.get_router_dependencies(router), - } + return { + "global_dependencies": self.get_global_dependencies(), + "router_dependencies": self.get_router_dependencies(router), + } diff --git a/robyn/robyn.pyi b/robyn/robyn.pyi index 8bd7b0a7d..6e4c1128f 100644 --- a/robyn/robyn.pyi +++ b/robyn/robyn.pyi @@ -29,6 +29,7 @@ class MiddlewareType(Enum): BEFORE_REQUEST: str AFTER_REQUEST: str """ + BEFORE_REQUEST: str AFTER_REQUEST: str @@ -47,6 +48,7 @@ class HttpMethod(Enum): TRACE: str CONNECT: str """ + GET: str POST: str PUT: str @@ -69,6 +71,7 @@ class FunctionInfo: args (dict): The arguments of the function kwargs (dict): The keyword arguments of the function """ + handler: Callable is_async: bool number_of_params: int diff --git a/robyn/router.py b/robyn/router.py index 9be3a6ca2..5237e5ea7 100644 --- a/robyn/router.py +++ b/robyn/router.py @@ -4,9 +4,8 @@ from functools import wraps from inspect import signature from types import CoroutineType -from typing import Any, Callable, Dict, List, NamedTuple, Union, Optional +from typing import Callable, Dict, List, NamedTuple, Union, Optional from robyn.authentication import AuthenticationHandler, AuthenticationNotConfiguredError -from robyn.dependency_injection import DependencyMap from robyn.robyn import FunctionInfo, HttpMethod, MiddlewareType, Request, Response from robyn import status_codes @@ -135,7 +134,6 @@ def inner_handler(*args, **kwargs): print("This is the params", params) print("This is the injected dependencies", injected_dependencies) - new_injected_dependencies = {} for dependency in injected_dependencies: if dependency in params: @@ -143,7 +141,6 @@ def inner_handler(*args, **kwargs): else: _logger.warning(f"Dependency {dependency} is not used in the handler {handler.__name__}") - if iscoroutinefunction(handler): function = FunctionInfo(async_inner_handler, True, number_of_params, params, new_injected_dependencies) self.routes.append(Route(route_type, endpoint, function, is_const)) @@ -168,7 +165,6 @@ def set_authentication_handler(self, authentication_handler: AuthenticationHandl self.authentication_handler = authentication_handler def add_route(self, middleware_type: MiddlewareType, endpoint: str, handler: Callable, injected_dependencies: Optional[dict]) -> Callable: - # add a docstring here params = dict(inspect.signature(handler).parameters) number_of_params = len(params) @@ -176,9 +172,6 @@ def add_route(self, middleware_type: MiddlewareType, endpoint: str, handler: Cal # need to do something here dependency_map = {} - - - function = FunctionInfo(handler, iscoroutinefunction(handler), number_of_params, {}, {}) self.route_middlewares.append(RouteMiddleware(middleware_type, endpoint, function)) return handler diff --git a/robyn/ws.py b/robyn/ws.py index b4409eca0..4a8576bfc 100644 --- a/robyn/ws.py +++ b/robyn/ws.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio -from inspect import signature import inspect from typing import TYPE_CHECKING, Callable from robyn.argument_parser import Config @@ -16,6 +15,7 @@ _logger = logging.getLogger(__name__) + class WebSocket: # should this be websocket router? """This is the python wrapper for the web socket that will be used here.""" @@ -35,7 +35,6 @@ def inner(handler): params = dict(inspect.signature(handler).parameters) num_params = len(params) is_async = asyncio.iscoroutinefunction(handler) - injected_dependencies = self.dependencies.get_dependency_map(self) @@ -50,4 +49,3 @@ def inner(handler): self.robyn_object.add_web_socket(self.endpoint, self) return inner -