1515from ninja .signature import is_async
1616from ninja .types import TCallable
1717
18- from ninja_extra .constants import DELETE , GET , PATCH , POST , PUT , ROUTE_METHODS
18+ from ninja_extra .constants import (
19+ DELETE ,
20+ GET ,
21+ PATCH ,
22+ POST ,
23+ PUT ,
24+ ROUTE_FUNCTION ,
25+ ROUTE_METHODS ,
26+ )
1927from ninja_extra .controllers .response import ControllerResponse , ControllerResponseMeta
2028from ninja_extra .permissions import BasePermission
2129from ninja_extra .schemas import RouteParameter
@@ -141,7 +149,7 @@ def _create_route_function(
141149 List [Union [Type [BasePermission ], BasePermission , Any ]]
142150 ] = None ,
143151 openapi_extra : Optional [Dict [str , Any ]] = None ,
144- ) -> RouteFunction :
152+ ) -> TCallable :
145153 if response is NOT_SET :
146154 response = get_type_hints (view_func ).get ("return" ) or NOT_SET
147155 route_obj = cls (
@@ -168,7 +176,8 @@ def _create_route_function(
168176 if route_obj .is_async :
169177 route_function_class = AsyncRouteFunction
170178
171- return route_function_class (route = route_obj )
179+ setattr (view_func , ROUTE_FUNCTION , route_function_class (route = route_obj ))
180+ return view_func
172181
173182 @classmethod
174183 def get (
@@ -192,7 +201,7 @@ def get(
192201 List [Union [Type [BasePermission ], BasePermission , Any ]]
193202 ] = None ,
194203 openapi_extra : Optional [Dict [str , Any ]] = None ,
195- ) -> Callable [[TCallable ], RouteFunction ]:
204+ ) -> Callable [[TCallable ], TCallable ]:
196205 """
197206 A GET Operation method decorator
198207 eg.
@@ -220,7 +229,7 @@ def get_operation(self):
220229 :return: Route[GET]
221230 """
222231
223- def decorator (view_func : TCallable ) -> RouteFunction :
232+ def decorator (view_func : TCallable ) -> TCallable :
224233 return cls ._create_route_function (
225234 view_func ,
226235 path = path ,
@@ -266,7 +275,7 @@ def post(
266275 List [Union [Type [BasePermission ], BasePermission , Any ]]
267276 ] = None ,
268277 openapi_extra : Optional [Dict [str , Any ]] = None ,
269- ) -> Callable [[TCallable ], RouteFunction ]:
278+ ) -> Callable [[TCallable ], TCallable ]:
270279 """
271280 A POST Operation method decorator
272281 eg.
@@ -294,7 +303,7 @@ def post_operation(self, create_schema: Schema):
294303 :return: Route[POST]
295304 """
296305
297- def decorator (view_func : TCallable ) -> RouteFunction :
306+ def decorator (view_func : TCallable ) -> TCallable :
298307 return cls ._create_route_function (
299308 view_func ,
300309 path = path ,
@@ -340,7 +349,7 @@ def delete(
340349 List [Union [Type [BasePermission ], BasePermission , Any ]]
341350 ] = None ,
342351 openapi_extra : Optional [Dict [str , Any ]] = None ,
343- ) -> Callable [[TCallable ], RouteFunction ]:
352+ ) -> Callable [[TCallable ], TCallable ]:
344353 """
345354 A DELETE Operation method decorator
346355 eg.
@@ -368,7 +377,7 @@ def delete_operation(self, some_id: int):
368377 :return: Route[DELETE]
369378 """
370379
371- def decorator (view_func : TCallable ) -> RouteFunction :
380+ def decorator (view_func : TCallable ) -> TCallable :
372381 return cls ._create_route_function (
373382 view_func ,
374383 path = path ,
@@ -414,7 +423,7 @@ def patch(
414423 List [Union [Type [BasePermission ], BasePermission , Any ]]
415424 ] = None ,
416425 openapi_extra : Optional [Dict [str , Any ]] = None ,
417- ) -> Callable [[TCallable ], RouteFunction ]:
426+ ) -> Callable [[TCallable ], TCallable ]:
418427 """
419428 A PATCH Operation method decorator
420429 eg.
@@ -443,7 +452,7 @@ def patch_operation(self, some_id: int):
443452 :return: Route[PATCH]
444453 """
445454
446- def decorator (view_func : TCallable ) -> RouteFunction :
455+ def decorator (view_func : TCallable ) -> TCallable :
447456 return cls ._create_route_function (
448457 view_func ,
449458 path = path ,
@@ -489,7 +498,7 @@ def put(
489498 List [Union [Type [BasePermission ], BasePermission , Any ]]
490499 ] = None ,
491500 openapi_extra : Optional [Dict [str , Any ]] = None ,
492- ) -> Callable [[TCallable ], RouteFunction ]:
501+ ) -> Callable [[TCallable ], TCallable ]:
493502 """
494503 A PUT Operation method decorator
495504 eg.
@@ -518,7 +527,7 @@ def put_operation(self, some_id: int):
518527 :return: Route[PUT]
519528 """
520529
521- def decorator (view_func : TCallable ) -> RouteFunction :
530+ def decorator (view_func : TCallable ) -> TCallable :
522531 return cls ._create_route_function (
523532 view_func ,
524533 path = path ,
@@ -565,7 +574,7 @@ def generic(
565574 List [Union [Type [BasePermission ], BasePermission , Any ]]
566575 ] = None ,
567576 openapi_extra : Optional [Dict [str , Any ]] = None ,
568- ) -> Callable [[TCallable ], RouteFunction ]:
577+ ) -> Callable [[TCallable ], TCallable ]:
569578 """
570579 A Custom Operation method decorator, for creating route with more than one operation
571580 eg.
@@ -595,7 +604,7 @@ def list_create(self, some_schema: Optional[Schema] = None):
595604 :return: Route[PATCH]
596605 """
597606
598- def decorator (view_func : TCallable ) -> RouteFunction :
607+ def decorator (view_func : TCallable ) -> TCallable :
599608 return cls ._create_route_function (
600609 view_func ,
601610 path = path ,
0 commit comments