Skip to content

Commit 465e45e

Browse files
committed
fixing minor linting issues
1 parent 1a2b531 commit 465e45e

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

dash/backend/fastapi.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import importlib.util
88
import time
99
import traceback
10+
import re
1011

1112
try:
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
@@ -23,28 +24,24 @@
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
3437
from dash.fingerprint import check_fingerprint
3538
from dash import _validate
3639
from dash.exceptions import (
3740
PreventUpdate,
38-
InvalidResourceError,
39-
InvalidCallbackReturnValue,
40-
BackgroundCallbackError,
4141
)
4242
from dash.backend import set_request_adapter
4343
from .base_server import BaseDashServer
4444

45-
import json
46-
import os
47-
4845
CONFIG_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)

dash/backend/flask.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import mimetypes
66
import time
77
import inspect
8+
import traceback
89
import flask
910
from dash.fingerprint import check_fingerprint
1011
from dash import _validate
12+
from dash._callback import _invoke_callback, _async_invoke_callback
1113
from dash.exceptions import PreventUpdate, InvalidResourceError
1214
from dash.backend import set_request_adapter
1315
from .base_server import BaseDashServer
14-
import traceback
1516

1617

1718
class FlaskDashServer(BaseDashServer):
@@ -47,13 +48,13 @@ def _invalid_resources_handler(err):
4748

4849
def _get_traceback(self, secret, error: Exception):
4950
try:
50-
from werkzeug.debug import tbtools
51+
from werkzeug.debug import (
52+
tbtools,
53+
) # pylint: disable=import-outside-toplevel
5154
except ImportError:
5255
tbtools = None
5356

5457
def _get_skip(error):
55-
from dash._callback import _invoke_callback, _async_invoke_callback
56-
5758
tb = error.__traceback__
5859
skip = 1
5960
while tb.tb_next is not None:
@@ -67,8 +68,6 @@ def _get_skip(error):
6768
return skip
6869

6970
def _do_skip(error):
70-
from dash._callback import _invoke_callback, _async_invoke_callback
71-
7271
tb = error.__traceback__
7372
while tb.tb_next is not None:
7473
if tb.tb_frame.f_code in [

dash/backend/quart.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
from contextvars import copy_context
77
import traceback
8+
import re
89

910
try:
1011
import quart
@@ -56,7 +57,7 @@ def register_assets_blueprint(
5657
)
5758
app.register_blueprint(bp)
5859

59-
def _get_traceback(self, secret, error: Exception):
60+
def _get_traceback(self, _secret, error: Exception):
6061
tb = error.__traceback__
6162
errors = traceback.format_exception(type(error), error, tb)
6263
pass_errs = []
@@ -73,15 +74,13 @@ def _get_traceback(self, secret, error: Exception):
7374
error_msg = str(error)
7475

7576
# Parse traceback lines to group by file
76-
import re
77-
7877
file_cards = []
7978
pattern = re.compile(r' File "(.+)", line (\d+), in (\w+)')
8079
lines = formatted_tb.split("\n")
8180
current_file = None
8281
card_lines = []
8382

84-
for i, line in enumerate(lines[:-1]): # Skip the last line (error message)
83+
for line in lines[:-1]: # Skip the last line (error message)
8584
match = pattern.match(line)
8685
if match:
8786
if current_file and card_lines:

dash/dash.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import mimetypes
1515
import hashlib
1616
import base64
17-
import traceback
1817
from urllib.parse import urlparse
1918
from typing import Any, Callable, Dict, Optional, Union, Sequence, Literal, List
2019

0 commit comments

Comments
 (0)