Skip to content

Commit 5211f6f

Browse files
committed
adjusments for formatting
1 parent 8c78089 commit 5211f6f

File tree

7 files changed

+118
-86
lines changed

7 files changed

+118
-86
lines changed

dash/backend/fastapi.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333

3434
from dash.fingerprint import check_fingerprint
3535
from dash import _validate
36-
from dash.exceptions import PreventUpdate, InvalidResourceError, InvalidCallbackReturnValue, BackgroundCallbackError
36+
from dash.exceptions import (
37+
PreventUpdate,
38+
InvalidResourceError,
39+
InvalidCallbackReturnValue,
40+
BackgroundCallbackError,
41+
)
3742
from dash.backend import set_request_adapter
3843
from .base_server import BaseDashServer
3944

@@ -42,16 +47,19 @@
4247

4348
CONFIG_PATH = "dash_config.json"
4449

50+
4551
def save_config(config):
4652
with open(CONFIG_PATH, "w") as f:
4753
json.dump(config, f)
4854

55+
4956
def load_config():
5057
if os.path.exists(CONFIG_PATH):
5158
with open(CONFIG_PATH, "r") as f:
5259
return json.load(f)
5360
return {}
5461

62+
5563
class FastAPIDashServer(BaseDashServer):
5664
def __init__(self):
5765
self.error_handling_mode = "prune"
@@ -96,7 +104,7 @@ def _get_traceback(self, secret, error: Exception):
96104
for err in errors:
97105
if self.error_handling_mode == "prune":
98106
if not callback_handled:
99-
if 'callback invoked' in str(err) and '_callback.py' in str(err):
107+
if "callback invoked" in str(err) and "_callback.py" in str(err):
100108
callback_handled = True
101109
continue
102110
pass_errs.append(err)
@@ -106,9 +114,10 @@ def _get_traceback(self, secret, error: Exception):
106114

107115
# Parse traceback lines to group by file
108116
import re
117+
109118
file_cards = []
110119
pattern = re.compile(r' File "(.+)", line (\d+), in (\w+)')
111-
lines = formatted_tb.split('\n')
120+
lines = formatted_tb.split("\n")
112121
current_file = None
113122
card_lines = []
114123

@@ -117,7 +126,9 @@ def _get_traceback(self, secret, error: Exception):
117126
if match:
118127
if current_file and card_lines:
119128
file_cards.append((current_file, card_lines))
120-
current_file = f'{match.group(1)} (line {match.group(2)}, in {match.group(3)})'
129+
current_file = (
130+
f"{match.group(1)} (line {match.group(2)}, in {match.group(3)})"
131+
)
121132
card_lines = [line]
122133
elif current_file:
123134
card_lines.append(line)
@@ -126,12 +137,16 @@ def _get_traceback(self, secret, error: Exception):
126137

127138
cards_html = ""
128139
for filename, card in file_cards:
129-
cards_html += f"""
140+
cards_html += (
141+
f"""
130142
<div class="error-card">
131143
<div class="error-card-header">{filename}</div>
132-
<pre class="error-card-traceback">"""+ '\n'.join(card) + """</pre>
144+
<pre class="error-card-traceback">"""
145+
+ "\n".join(card)
146+
+ """</pre>
133147
</div>
134148
"""
149+
)
135150

136151
html = f"""
137152
<!doctype html>
@@ -198,7 +213,6 @@ def register_prune_error_handler(self, _app, _secret, prune_errors):
198213
else:
199214
self.error_handling_mode = "raise"
200215

201-
202216
def _html_response_wrapper(self, view_func):
203217
async def wrapped(*_args, **_kwargs):
204218
# If view_func is a function, call it; if it's a string, use it directly
@@ -221,9 +235,7 @@ def setup_catchall(self, dash_app):
221235
@dash_app.server.on_event("startup")
222236
def _setup_catchall():
223237
config = load_config()
224-
dash_app.enable_dev_tools(
225-
**config, first_run=False
226-
)
238+
dash_app.enable_dev_tools(**config, first_run=False)
227239

228240
async def catchall(request: Request):
229241
adapter = FastAPIRequestAdapter()
@@ -260,13 +272,15 @@ def after_request(self, app, func):
260272

261273
def run(self, dash_app, app, host, port, debug, **kwargs):
262274
frame = inspect.stack()[2]
263-
config = dict({"debug": debug} if debug else {}, **{
264-
f'dev_tools_{k}': v for k, v in dash_app._dev_tools.items()})
275+
config = dict(
276+
{"debug": debug} if debug else {},
277+
**{f"dev_tools_{k}": v for k, v in dash_app._dev_tools.items()},
278+
)
265279
save_config(config)
266280
if debug:
267-
if kwargs.get('reload') is None:
268-
kwargs['reload'] = True
269-
if kwargs.get('reload'):
281+
if kwargs.get("reload") is None:
282+
kwargs["reload"] = True
283+
if kwargs.get("reload"):
270284
# Dynamically determine the module name from the file path
271285
file_path = frame.filename
272286
module_name = importlib.util.spec_from_file_location("app", file_path).name
@@ -305,7 +319,7 @@ async def middleware(request, call_next):
305319
if self.error_handling_mode in ["raise", "prune"]:
306320
# Prune the traceback to remove internal Dash calls
307321
tb = self._get_traceback(None, e)
308-
return Response(content=tb, media_type='text/html', status_code=500)
322+
return Response(content=tb, media_type="text/html", status_code=500)
309323
return JSONResponse(
310324
status_code=500,
311325
content={"error": "InternalServerError", "message": str(e.args[0])},

dash/backend/flask.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ def _do_skip(error):
8282
if hasattr(tbtools, "get_current_traceback"):
8383
return tbtools.get_current_traceback(skip=_get_skip(error)).render_full()
8484
if hasattr(tbtools, "DebugTraceback"):
85-
return tbtools.DebugTraceback(error, skip=_get_skip(error)).render_debugger_html(True, secret, True)
85+
return tbtools.DebugTraceback(
86+
error, skip=_get_skip(error)
87+
).render_debugger_html(True, secret, True)
8688
return "".join(traceback.format_exception(type(error), error, _do_skip(error)))
8789

8890
def register_prune_error_handler(self, app, secret, prune_errors):
8991
if prune_errors:
92+
9093
@app.errorhandler(Exception)
9194
def _wrap_errors(error):
9295
tb = self._get_traceback(secret, error)

dash/backend/quart.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _get_traceback(self, secret, error: Exception):
6464
for err in errors:
6565
if self.error_handling_mode == "prune":
6666
if not callback_handled:
67-
if 'callback invoked' in str(err) and '_callback.py' in str(err):
67+
if "callback invoked" in str(err) and "_callback.py" in str(err):
6868
callback_handled = True
6969
continue
7070
pass_errs.append(err)
@@ -74,9 +74,10 @@ def _get_traceback(self, secret, error: Exception):
7474

7575
# Parse traceback lines to group by file
7676
import re
77+
7778
file_cards = []
7879
pattern = re.compile(r' File "(.+)", line (\d+), in (\w+)')
79-
lines = formatted_tb.split('\n')
80+
lines = formatted_tb.split("\n")
8081
current_file = None
8182
card_lines = []
8283

@@ -85,7 +86,9 @@ def _get_traceback(self, secret, error: Exception):
8586
if match:
8687
if current_file and card_lines:
8788
file_cards.append((current_file, card_lines))
88-
current_file = f'{match.group(1)} (line {match.group(2)}, in {match.group(3)})'
89+
current_file = (
90+
f"{match.group(1)} (line {match.group(2)}, in {match.group(3)})"
91+
)
8992
card_lines = [line]
9093
elif current_file:
9194
card_lines.append(line)
@@ -94,12 +97,16 @@ def _get_traceback(self, secret, error: Exception):
9497

9598
cards_html = ""
9699
for filename, card in file_cards:
97-
cards_html += f"""
100+
cards_html += (
101+
f"""
98102
<div class="error-card">
99103
<div class="error-card-header">{filename}</div>
100-
<pre class="error-card-traceback">""" + '\n'.join(card) + """</pre>
104+
<pre class="error-card-traceback">"""
105+
+ "\n".join(card)
106+
+ """</pre>
101107
</div>
102108
"""
109+
)
103110

104111
html = f"""
105112
<!doctype html>
@@ -169,7 +176,7 @@ def register_prune_error_handler(self, app, secret, prune_errors):
169176
@app.errorhandler(Exception)
170177
async def _wrap_errors(error):
171178
tb = self._get_traceback(secret, error)
172-
return Response(tb, status=500, content_type='text/html')
179+
return Response(tb, status=500, content_type="text/html")
173180

174181
def register_timing_hooks(self, app, _first_run): # parity with Flask factory
175182
@app.before_request

dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ const MAX_MESSAGE_LENGTH = 40;
122122
/* eslint-disable no-inline-comments */
123123
function UnconnectedErrorContent({error, base}) {
124124
// Helper to detect full HTML document
125-
const isFullHtmlDoc = typeof error.html === 'string' &&
125+
const isFullHtmlDoc =
126+
typeof error.html === 'string' &&
126127
error.html.trim().toLowerCase().startsWith('<!doctype');
127128

128129
// Helper to detect HTML fragment
129-
const isHtmlFragment = typeof error.html === 'string' &&
130-
error.html.trim().startsWith('<');
130+
const isHtmlFragment =
131+
typeof error.html === 'string' && error.html.trim().startsWith('<');
131132

132133
return (
133134
<div className='error-container'>

dash/dash.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,12 @@ def verify_url_part(served_part, url_part, part_name):
22922292
)
22932293
else:
22942294
self.backend.run(
2295-
self, self.server, host=host, port=port, debug=debug, **flask_run_options
2295+
self,
2296+
self.server,
2297+
host=host,
2298+
port=port,
2299+
debug=debug,
2300+
**flask_run_options,
22962301
)
22972302

22982303
def enable_pages(self) -> None:

dash/testing/application_runners.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ def run():
174174
module = app.server.__class__.__module__
175175
# FastAPI support
176176
if not module.startswith("flask"):
177-
app.run(
178-
**options
179-
)
177+
app.run(**options)
180178
# Dash/Flask fallback
181179
else:
182180
app.run(threaded=True, **options)
@@ -240,9 +238,7 @@ def target():
240238
module = app.server.__class__.__module__
241239
# FastAPI support
242240
if not module.startswith("flask"):
243-
app.run(
244-
**options
245-
)
241+
app.run(**options)
246242
# Dash/Flask fallback
247243
else:
248244
app.run(threaded=True, **options)

0 commit comments

Comments
 (0)