@@ -81,9 +81,9 @@ def __init__(
81
81
self .throttle_objects : List [BaseThrottle ] = []
82
82
if throttle is not NOT_SET :
83
83
for th in throttle : # type: ignore
84
- assert isinstance (
85
- th , BaseThrottle
86
- ), "Throttle should be an instance of BaseThrottle"
84
+ assert isinstance (th , BaseThrottle ), (
85
+ "Throttle should be an instance of BaseThrottle"
86
+ )
87
87
self .throttle_objects .append (th )
88
88
89
89
self .signature = ViewSignature (self .path , self .view_func )
@@ -163,9 +163,9 @@ def set_api_instance(self, api: "NinjaAPI", router: "Router") -> None:
163
163
if router .throttle != NOT_SET :
164
164
_t = router .throttle
165
165
self .throttle_objects = isinstance (_t , BaseThrottle ) and [_t ] or _t # type: ignore
166
- assert all (
167
- isinstance ( th , BaseThrottle ) for th in self . throttle_objects
168
- ), "Throttle should be an instance of BaseThrottle"
166
+ assert all (isinstance ( th , BaseThrottle ) for th in self . throttle_objects ), (
167
+ "Throttle should be an instance of BaseThrottle"
168
+ )
169
169
170
170
if self .tags is None :
171
171
if router .tags is not None :
@@ -207,7 +207,11 @@ def _run_authentication(self, request: HttpRequest) -> Optional[HttpResponse]:
207
207
if is_async_callable (callback ) or getattr (callback , "is_async" , False ):
208
208
result = callback (request )
209
209
if inspect .iscoroutine (result ):
210
- result = async_to_sync (callback )(request )
210
+
211
+ async def await_result (cor ):
212
+ return await cor
213
+
214
+ result = async_to_sync (await_result )(result )
211
215
else :
212
216
result = callback (request )
213
217
except Exception as exc :
0 commit comments