77import importlib .util
88import time
99import traceback
10+ import re
1011
1112try :
1213 import uvicorn
1314 from fastapi import FastAPI , Request , Response
14- from fastapi .responses import JSONResponse , PlainTextResponse
15+ from fastapi .responses import JSONResponse
1516 from fastapi .staticfiles import StaticFiles
1617 from starlette .responses import Response as StarletteResponse
1718 from starlette .datastructures import MutableHeaders
2324 Request = None
2425 Response = None
2526 JSONResponse = None
26- PlainTextResponse = None
2727 StaticFiles = None
2828 StarletteResponse = None
2929 MutableHeaders = None
3030 create_model = None
3131 Any = None
3232 Optional = None
3333
34+
35+ import json
36+ import os
3437from dash .fingerprint import check_fingerprint
3538from dash import _validate
3639from dash .exceptions import (
3740 PreventUpdate ,
38- InvalidResourceError ,
39- InvalidCallbackReturnValue ,
40- BackgroundCallbackError ,
4141)
4242from dash .backend import set_request_adapter
4343from .base_server import BaseDashServer
4444
45- import json
46- import os
47-
4845CONFIG_PATH = "dash_config.json"
4946
5047
@@ -93,10 +90,8 @@ def register_assets_blueprint(
9390
9491 def register_error_handlers (self , app ):
9592 self .error_handling_mode = "prune"
96- # FastAPI uses exception handlers, but we will handle errors in middleware
97- pass
9893
99- def _get_traceback (self , secret , error : Exception ):
94+ def _get_traceback (self , _secret , error : Exception ):
10095 tb = error .__traceback__
10196 errors = traceback .format_exception (type (error ), error , tb )
10297 pass_errs = []
@@ -113,15 +108,13 @@ def _get_traceback(self, secret, error: Exception):
113108 error_msg = str (error )
114109
115110 # Parse traceback lines to group by file
116- import re
117-
118111 file_cards = []
119112 pattern = re .compile (r' File "(.+)", line (\d+), in (\w+)' )
120113 lines = formatted_tb .split ("\n " )
121114 current_file = None
122115 card_lines = []
123116
124- for i , line in enumerate ( lines [:- 1 ]) : # Skip the last line (error message)
117+ for line in lines [:- 1 ]: # Skip the last line (error message)
125118 match = pattern .match (line )
126119 if match :
127120 if current_file and card_lines :
@@ -274,7 +267,9 @@ def run(self, dash_app, app, host, port, debug, **kwargs):
274267 frame = inspect .stack ()[2 ]
275268 config = dict (
276269 {"debug" : debug } if debug else {},
277- ** {f"dev_tools_{ k } " : v for k , v in dash_app ._dev_tools .items ()},
270+ ** {
271+ f"dev_tools_{ k } " : v for k , v in dash_app ._dev_tools .items ()
272+ }, # pylint: disable=protected-access
278273 )
279274 save_config (config )
280275 if debug :
@@ -307,7 +302,7 @@ def jsonify(self, obj):
307302 def get_request_adapter (self ):
308303 return FastAPIRequestAdapter
309304
310- def _make_before_middleware (self , func ):
305+ def _make_before_middleware (self , _func ):
311306 async def middleware (request , call_next ):
312307 try :
313308 response = await call_next (request )
0 commit comments