Skip to content

Commit efb20c1

Browse files
codingjoetim-schilling
authored andcommitted
Address new ruff 0.16 and biome 2.5.5 warnings
1 parent 7a75760 commit efb20c1

23 files changed

Lines changed: 71 additions & 83 deletions

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.5.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.5.5/schema.json",
33
"formatter": {
44
"enabled": true,
55
"useEditorconfig": true

debug_toolbar/apps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ def check_panel_configs(app_configs, **kwargs):
177177

178178
errors = []
179179
for panel_class in DebugToolbar.get_panel_classes():
180-
for check_message in panel_class.run_checks():
181-
errors.append(check_message)
180+
errors.extend(panel_class.run_checks())
182181
return errors
183182

184183

debug_toolbar/middleware.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ def show_toolbar(request: HttpRequest) -> bool:
3434
return False
3535

3636
# Test: settings
37-
if request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS:
38-
return True
39-
40-
# No test passed
41-
return False
37+
return request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS
4238

4339

4440
def show_toolbar_with_docker(request: HttpRequest) -> bool:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from debug_toolbar.panels.history.panel import HistoryPanel
22

3-
__all__: list[str] = [HistoryPanel.panel_id]
3+
__all__: list[str] = ["HistoryPanel"]

debug_toolbar/panels/profiling.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def func_std_string(self): # match what old profile produced
8787
)
8888

8989
def subfuncs(self):
90-
h, s, v = self.hsv
90+
h, s, _v = self.hsv
9191
count = len(self.statobj.all_callees[self.func])
9292
for i, (func, stats) in enumerate(self.statobj.all_callees[self.func].items()):
9393
h1 = h + ((i + 1) / count) / (self.depth + 1)
@@ -109,25 +109,25 @@ def tottime(self):
109109
return self.stats[2]
110110

111111
def cumtime(self):
112-
cc, nc, tt, ct = self.stats
113-
return self.stats[3]
112+
_cc, _nc, _tt, ct = self.stats
113+
return ct
114114

115115
def tottime_per_call(self):
116-
cc, nc, tt, ct = self.stats
116+
_cc, nc, tt, _ct = self.stats
117117

118-
if nc == 0:
118+
try:
119+
return tt / nc
120+
except ZeroDivisionError:
119121
return 0
120122

121-
return tt / nc
122-
123123
def cumtime_per_call(self):
124-
cc, nc, tt, ct = self.stats
124+
cc, _nc, _tt, ct = self.stats
125125

126-
if cc == 0:
126+
try:
127+
return ct / cc
128+
except ZeroDivisionError:
127129
return 0
128130

129-
return ct / cc
130-
131131
def indent(self):
132132
return 16 * self.depth
133133

debug_toolbar/panels/redirects.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ def _process_response(self, response):
2222
"""
2323
Common response processing logic.
2424
"""
25-
if 300 <= response.status_code < 400:
26-
if redirect_to := response.get("Location"):
27-
response = self.get_interception_response(response, redirect_to)
28-
response.render()
25+
if 300 <= response.status_code < 400 and (
26+
redirect_to := response.get("Location")
27+
):
28+
response = self.get_interception_response(response, redirect_to)
29+
response.render()
2930
return response
3031

3132
async def aprocess_request(self, request, response_coroutine):

debug_toolbar/panels/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def safe_pformat(obj):
1212
try:
1313
return pformat(obj)
14-
except Exception as e:
14+
except ValueError as e:
1515
return f"<unformattable {type(obj).__name__}: {e!r}>"
1616

1717

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from debug_toolbar.panels.sql.panel import SQLPanel
22

3-
__all__ = [SQLPanel.panel_id]
3+
__all__ = ["SQLPanel"]

debug_toolbar/panels/sql/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.db import DatabaseError
12
from django.http import HttpResponseBadRequest, JsonResponse
23
from django.template.loader import render_to_string
34
from django.views.decorators.csrf import csrf_exempt
@@ -88,7 +89,7 @@ def sql_profile(request):
8889
result_error = None
8990
try:
9091
result, headers = form.profile()
91-
except Exception:
92+
except DatabaseError:
9293
result_error = (
9394
"Profiling is either not available or not supported by your database."
9495
)

debug_toolbar/panels/staticfiles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def __init__(self, *args, **kwargs):
5757

5858
@classmethod
5959
def ready(cls):
60-
cls = storage.staticfiles_storage.__class__
61-
if URLMixin not in cls.mro():
62-
cls.__bases__ = (URLMixin, *cls.__bases__)
60+
klass = storage.staticfiles_storage.__class__
61+
if URLMixin not in klass.mro():
62+
klass.__bases__ = (URLMixin, *klass.__bases__)
6363

6464
def _store_static_files_signal_handler(self, sender, staticfile, **kwargs):
6565
# Only record the static file if the request_id matches the one
@@ -114,7 +114,7 @@ def get_staticfiles_finders(self):
114114
else:
115115
prefixed_path = path
116116
finder_cls = finder.__class__
117-
finder_path = ".".join([finder_cls.__module__, finder_cls.__name__])
117+
finder_path = f"{finder_cls.__module__}.{finder_cls.__name__}"
118118
real_path = finder_storage.path(path)
119119
payload = (prefixed_path, real_path)
120120
finders_mapping.setdefault(finder_path, []).append(payload)

0 commit comments

Comments
 (0)