@@ -94,13 +94,14 @@ def _remove_config(config_path):
9494 pass
9595
9696
97- class FastAPIDashServer (BaseDashServer ):
97+ class FastAPIDashServer (BaseDashServer [ FastAPI ] ):
9898 def __init__ (self , server : FastAPI ):
99+ super ().__init__ (server )
99100 self .server_type = "fastapi"
100- self .server : FastAPI = server
101101 self .error_handling_mode = "ignore"
102102 self .request_adapter = FastAPIRequestAdapter
103103 self ._before_request_funcs = []
104+ self ._before_middleware_added = False
104105
105106 fname = inspect .stack ()[2 ]
106107 file_path = fname .filename
@@ -114,7 +115,6 @@ def __init__(self, server: FastAPI):
114115 hash_digest = hashlib .sha256 (file_path .encode ("utf-8" )).hexdigest ()
115116 config_filename = f"{ hash_digest } .json"
116117 self ._CONFIG_PATH = os .path .join (config_dir , config_filename )
117- super ().__init__ ()
118118
119119 def __call__ (self , * args : Any , ** kwargs : Any ):
120120 # ASGI: (scope, receive, send)
@@ -232,7 +232,7 @@ def has_request_context(self) -> bool:
232232
233233 def run (self , dash_app : Dash , host , port , debug , ** kwargs ):
234234 frame = inspect .stack ()[2 ]
235- dev_tools = dash_app ._dev_tools # pylint- disable=W0212
235+ dev_tools = dash_app ._dev_tools # pylint: disable=W0212
236236 config = dict (
237237 {"debug" : debug } if debug else {"debug" : False },
238238 ** {f"dev_tools_{ k } " : v for k , v in dev_tools .items ()},
@@ -260,6 +260,7 @@ def run(self, dash_app: Dash, host, port, debug, **kwargs):
260260 # Add any other kwargs as CLI args if needed
261261
262262 try :
263+ # pylint: disable=R1732
263264 proc = subprocess .Popen (uvicorn_args , env = os .environ .copy ())
264265 proc .wait ()
265266 finally :
@@ -293,7 +294,7 @@ async def middleware(request, call_next):
293294 return response
294295 except PreventUpdate :
295296 return Response (status_code = 204 )
296- except Exception as e :
297+ except Exception as e : # pylint: disable=W0718
297298 if self .error_handling_mode in ["raise" , "prune" ]:
298299 tb = self ._get_traceback (None , e )
299300 return Response (content = tb , media_type = "text/html" , status_code = 500 )
@@ -465,14 +466,18 @@ async def view_func(_request: Request, body: dict = Body(...)):
465466 )
466467
467468 def enable_compression (self ) -> None :
468- from fastapi .middleware .gzip import GZipMiddleware
469+ from fastapi .middleware .gzip import (
470+ GZipMiddleware ,
471+ ) # pylint: disable=import-outside-toplevel
469472
470473 self .server .add_middleware (GZipMiddleware , minimum_size = 500 )
471- config = _load_config ()
474+ config = _load_config (self . _CONFIG_PATH )
472475 if "COMPRESS_ALGORITHM" not in config :
473- config ["COMPRESS_ALGORITHM" ] = ["gzip" ]
476+ config ["COMPRESS_ALGORITHM" ] = [
477+ "gzip"
478+ ] # pylint: disable=no-value-for-parameter
474479
475- _save_config (config )
480+ _save_config (self . _CONFIG_PATH , config )
476481
477482
478483class FastAPIRequestAdapter (RequestAdapter ):
0 commit comments