99from queue import Queue as ThreadQueue
1010from threading import Event as ThreadEvent
1111from threading import Thread
12- from typing import Any , Callable , Dict , NamedTuple , Optional , Union , cast
12+ from typing import Any , Callable , Dict , NamedTuple , NoReturn , Optional , Union , cast
1313
1414from flask import (
1515 Blueprint ,
@@ -84,13 +84,12 @@ async def serve_development_app(
8484
8585 server : Ref [BaseWSGIServer ] = Ref ()
8686
87- def run_server () -> None : # pragma: no cover
88- # we don't cover this function because coverage doesn't work right in threads
87+ def run_server () -> None :
8988 server .current = make_server (host , port , app , threaded = True )
9089 if started :
9190 loop .call_soon_threadsafe (started .set )
9291 try :
93- server .current .serve_forever ()
92+ server .current .serve_forever () # type: ignore
9493 finally :
9594 loop .call_soon_threadsafe (stopped .set )
9695
@@ -178,12 +177,8 @@ def model_stream(ws: WebSocket, path: str = "") -> None:
178177 def send (value : Any ) -> None :
179178 ws .send (json .dumps (value ))
180179
181- def recv () -> Optional [LayoutEvent ]:
182- event = ws .receive ()
183- if event is not None :
184- return LayoutEvent (** json .loads (event ))
185- else :
186- return None
180+ def recv () -> LayoutEvent :
181+ return LayoutEvent (** json .loads (ws .receive ()))
187182
188183 dispatch_in_thread (ws , path , constructor (), send , recv )
189184
@@ -197,7 +192,7 @@ def dispatch_in_thread(
197192 component : ComponentType ,
198193 send : Callable [[Any ], None ],
199194 recv : Callable [[], Optional [LayoutEvent ]],
200- ) -> None :
195+ ) -> NoReturn :
201196 dispatch_thread_info_created = ThreadEvent ()
202197 dispatch_thread_info_ref : idom .Ref [Optional [_DispatcherThreadInfo ]] = idom .Ref (None )
203198
@@ -255,21 +250,14 @@ def run_send() -> None:
255250 try :
256251 while True :
257252 value = recv ()
258- if value is None :
259- stop .set ()
260- break
261- # BUG: https://github.com/nedbat/coveragepy/issues/1012
262- # Coverage isn't able to support concurrency coverage for both threading and gevent
263- dispatch_thread_info .dispatch_loop .call_soon_threadsafe ( # pragma: no cover
253+ dispatch_thread_info .dispatch_loop .call_soon_threadsafe (
264254 dispatch_thread_info .async_recv_queue .put_nowait , value
265255 )
266256 finally :
267257 dispatch_thread_info .dispatch_loop .call_soon_threadsafe (
268258 dispatch_thread_info .dispatch_future .cancel
269259 )
270260
271- return None
272-
273261
274262@dataclass
275263class Connection :
@@ -290,9 +278,3 @@ class _DispatcherThreadInfo(NamedTuple):
290278 dispatch_future : "asyncio.Future[Any]"
291279 thread_send_queue : "ThreadQueue[LayoutUpdate]"
292280 async_recv_queue : "AsyncQueue[LayoutEvent]"
293-
294-
295- def _join_url_paths (* args : str ) -> str :
296- # urllib.parse.urljoin performs more logic than is needed. Thus we need a util func
297- # to join paths as if they were POSIX paths.
298- return "/" .join (map (lambda x : str (x ).rstrip ("/" ), filter (None , args )))
0 commit comments