8000 [pre-commit.ci] pre-commit autoupdate by pre-commit-ci[bot] · Pull Request #2421 · django-commons/django-debug-toolbar · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address new ruff 0.16 and biome 2.5.5 warnings
  • Loading branch information
codingjoe authored and tim-schilling committed Jul 31, 2026
commit 385dad4d799464b39d0020e63da5c62c8289e295
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.2/schema.json",
"$schema": "https://biomejs.dev/schemas/2.5.5/schema.json",
"formatter": {
"enabled": true,
"useEditorconfig": true
Expand Down
3 changes: 1 addition & 2 deletions debug_toolbar/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def check_panel_configs(app_configs, **kwargs):

errors = []
for panel_class in DebugToolbar.get_panel_classes():
for check_message in panel_class.run_checks():
errors.append(check_message)
errors.extend(panel_class.run_checks())
return errors


Expand Down
6 changes: 1 addition & 5 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def show_toolbar(request: HttpRequest) -> bool:
return False

# Test: settings
if request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS:
return True

# No test passed
return False
return request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS


def show_toolbar_with_docker(request: HttpRequest) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/history/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from debug_toolbar.panels.history.panel import HistoryPanel

__all__: list[str] = [HistoryPanel.panel_id]
__all__: list[str] = ["HistoryPanel"]
22 changes: 11 additions & 11 deletions debug_toolbar/panels/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def func_std_string(self): # match what old profile produced
)

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

def cumtime(self):
cc, nc, tt, ct = self.stats
return self.stats[3]
_cc, _nc, _tt, ct = self.stats
return ct

def tottime_per_call(self):
cc, nc, tt, ct = self.stats
_cc, nc, tt, _ct = self.stats

if nc == 0:
try:
return tt / nc
except ZeroDivisionError:
return 0

return tt / nc

def cumtime_per_call(self):
cc, nc, tt, ct = self.stats
cc, _nc, _tt, ct = self.stats

if cc == 0:
try:
return ct / cc
except ZeroDivisionError:
return 0

return ct / cc

def indent(self):
return 16 * self.depth

Expand Down
9 changes: 5 additions & 4 deletions debug_toolbar/panels/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def _process_response(self, response):
"""
Common response processing logic.
"""
if 300 <= response.status_code < 400:
if redirect_to := response.get("Location"):
response = self.get_interception_response(response, redirect_to)
response.render()
if 300 <= response.status_code < 400 and (
redirect_to := response.get("Location")
):
response = self.get_interception_response(response, redirect_to)
response.render()
return response

async def aprocess_request(self, request, response_coroutine):
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def safe_pformat(obj):
try:
return pformat(obj)
except Exception as e:
except ValueError as e:
return f"<unformattable {type(obj).__name__}: {e!r}>"


Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from debug_toolbar.panels.sql.panel import SQLPanel

__all__ = [SQLPanel.panel_id]
__all__ = ["SQLPanel"]
3 changes: 2 additions & 1 deletion debug_toolbar/panels/sql/views.py
133E
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import DatabaseError
from django.http import HttpResponseBadRequest, JsonResponse
from django.template.loader import render_to_string
from django.views.decorators.csrf import csrf_exempt
Expand Down Expand Up @@ -88,7 +89,7 @@ def sql_profile(request):
result_error = None
try:
result, headers = form.profile()
except Exception:
except DatabaseError:
result_error = (
"Profiling is either not available or not supported by your database."
)
Expand Down
8 changes: 4 additions & 4 deletions debug_toolbar/panels/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def __init__(self, *args, **kwargs):

@classmethod
def ready(cls):
cls = storage.staticfiles_storage.__class__
if URLMixin not in cls.mro():
cls.__bases__ = (URLMixin, *cls.__bases__)
klass = storage.staticfiles_storage.__class__
if URLMixin not in klass.mro():
klass.__bases__ = (URLMixin, *klass.__bases__)

def _store_static_files_signal_handler(self, sender, staticfile, **kwargs):
# Only record the static file if the request_id matches the one
Expand Down Expand Up @@ -114,7 +114,7 @@ def get_staticfiles_finders(self):
else:
prefixed_path = path
finder_cls = finder.__class__
finder_path = ".".join([finder_cls.__module__, finder_cls.__name__])
finder_path = f"{finder_cls.__module__}.{finder_cls.__name__}"
real_path = finder_storage.path(path)
payload = (prefixed_path, real_path)
finders_mapping.setdefault(finder_path, []).append(payload)
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/templates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from debug_toolbar.panels.templates.panel import TemplatesPanel

__all__ = [TemplatesPanel.panel_id]
__all__ = ["TemplatesPanel"]
2 changes: 1 addition & 1 deletion debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def process_context_list(self, context_layers):
temp_layer[key] = "<<triggers database query>>"
except UnicodeEncodeError:
temp_layer[key] = "<<Unicode encode error>>"
except Exception:
except Exception: # noqa: BLE001
temp_layer[key] = "<<unhandled exception>>"
else:
temp_layer[key] = value
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/panels/templates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def template_source(request):
return HttpResponseBadRequest('"template_origin" key is required')
try:
template_origin_name = signing.loads(template_origin_name)
except Exception:
except signing.BadSignature:
return HttpResponseBadRequest('"template_origin" is invalid')
template_name = request.GET.get("template", template_origin_name)

Expand Down
20 changes: 10 additions & 10 deletions debug_toolbar/static/debug_toolbar/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@
color: #999;
}

#djDebug #djDebugToolbar li a:hover {
color: #111;
background-color: #ffc;
}

#djDebug #djDebugToolbar li.djdt-active {
background: #333;
}
Expand All @@ -252,11 +247,6 @@
font-size: 150%;
}

#djDebug #djDebugToolbar li.djdt-active a:hover {
color: #b36a60;
background-color: transparent;
}

#djDebug #djDebugToolbar li small {
font-size: 12px;
color: #999;
Expand Down Expand Up @@ -1233,3 +1223,13 @@ To regenerate:
#djDebug .djdt-community-panel a:hover {
text-decoration: underline;
}

#djDebug #djDebugToolbar li a:hover {
color: #111;
background-color: #ffc;
}

#djDebug #djDebugToolbar li.djdt-active a:hover {
color: #b36a60;
background-color: transparent;
}
7 changes: 4 additions & 3 deletions debug_toolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_template_info() -> dict[str, Any] | None:
template_info = get_template_context(node, context)
break
cur_frame = cur_frame.f_back
except Exception:
except Exception: # noqa: S110, BLE001
pass
del cur_frame
return template_info
Expand Down Expand Up @@ -203,8 +203,9 @@ def getframeinfo(frame: Any, context: int = 1) -> inspect.Traceback:
if context > 0:
start = lineno - 1 - context // 2
try:
lines, lnum = inspect.findsource(frame)
except Exception: # findsource raises platform-dependant exceptions
lines, _lnum = inspect.findsource(frame)
except Exception: # noqa: BLE001
# findsource raises platform-dependant exceptions
lines = index = None
else:
start = max(start, 1)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

project = "Django Debug Toolbar"
copyright = "{}, Django Debug Toolbar developers and contributors"
copyright = copyright.format(datetime.date.today().year)
copyright = copyright.format(datetime.datetime.now(datetime.timezone.utc).year)

# The full version, including alpha/beta/rc tags
release = "6.2.0"
Expand Down
2 changes: 1 addition & 1 deletion example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Application definition

INSTALLED_APPS = [
*(["daphne"] if os.getenv("ASYNC_SERVER", False) else []), # noqa: FBT003
*(["daphne"] if os.getenv("ASYNC_SERVER", "") else []),
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ lint.extend-select = [
"W", # pycodestyle warnings
]
lint.extend-ignore = [
"B905", # Allow zip() without strict=
"E501", # Ignore line length violations
"UP031", # It's not always wrong to use percent-formatting
"B905", # Allow zip() without strict=
"E501", # Ignore line length violations
"RUF012", # Allow mutable class attributes
"UP031", # It's not always wrong to use percent-formatting
]
lint.per-file-ignores."*/migrat*/*" = [
"N806", # Allow using PascalCase model names in migrations
Expand Down
10 changes: 5 additions & 5 deletions tests/panels/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_history_headers(self):
"""Validate the headers injected from the history panel."""
DebugToolbar.get_observe_request.cache_clear()
response = self.client.get("/json_view/")
request_id = list(get_store().request_ids())[0]
request_id = next(iter(get_store().request_ids()))
self.assertEqual(response.headers["djdt-request-id"], request_id)

def test_history_headers_unobserved(self):
Expand All @@ -128,7 +128,7 @@ def test_history_headers_unobserved(self):
def test_history_sidebar(self):
"""Validate the history sidebar view."""
self.client.get("/json_view/")
request_id = list(get_store().request_ids())[0]
request_id = next(iter(get_store().request_ids()))
data = {"request_id": request_id, "exclude_history": True}
response = self.client.get(reverse("djdt:history_sidebar"), data=data)
self.assertEqual(response.status_code, 200)
Expand All @@ -143,7 +143,7 @@ def test_history_sidebar_includes_history(self):
panel_keys = copy.copy(self.PANEL_KEYS)
panel_keys.add(HistoryPanel.panel_id)
panel_keys.add(RedirectsPanel.panel_id)
request_id = list(get_store().request_ids())[0]
request_id = next(iter(get_store().request_ids()))
data = {"request_id": request_id}
response = self.client.get(reverse("djdt:history_sidebar"), data=data)
self.assertEqual(response.status_code, 200)
Expand All @@ -158,7 +158,7 @@ def test_history_sidebar_includes_history(self):
def test_history_sidebar_expired_request_id(self):
"""Validate the history sidebar view."""
self.client.get("/json_view/")
request_id = list(get_store().request_ids())[0]
request_id = next(iter(get_store().request_ids()))
data = {"request_id": request_id, "exclude_history": True}
response = self.client.get(reverse("djdt:history_sidebar"), data=data)
self.assertEqual(response.status_code, 200)
Expand All @@ -176,7 +176,7 @@ def test_history_sidebar_expired_request_id(self):
self.assertEqual(response.json(), {})

# Querying with latest request_id
latest_request_id = list(get_store().request_ids())[0]
latest_request_id = next(iter(get_store().request_ids()))
data = {"request_id": latest_request_id, "exclude_history": True}
response = self.client.get(reverse("djdt:history_sidebar"), data=data)
self.assertEqual(response.status_code, 200)
Expand Down
31 changes: 9 additions & 22 deletions tests/panels/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,37 +495,24 @@ def test_raw_query_param_conversion(self):

list(
User.objects.raw(
" ".join(
[
"SELECT *",
"FROM auth_user",
"WHERE first_name = %s",
"AND is_staff = %s",
"AND is_superuser = %s",
"AND date_joined = %s",
]
),
params=["Foo", True, False, datetime.datetime(2017, 12, 22, 16, 7, 1)],
"SELECT * FROM auth_user WHERE first_name = %s AND is_staff = %s AND is_superuser = %s AND date_joined = %s",
params=[
"Foo",
True,
False,
datetime.datetime(2017, 12, 22, 16, 7, 1), # noqa: DTZ001
],
)
)

list(
User.objects.raw(
" ".join(
[
"SELECT *",
"FROM auth_user",
"WHERE first_name = %(first_name)s",
"AND is_staff = %(is_staff)s",
"AND is_superuser = %(is_superuser)s",
"AND date_joined = %(date_joined)s",
]
),
"SELECT * FROM auth_user WHERE first_name = %(first_name)s AND is_staff = %(is_staff)s AND is_superuser = %(is_superuser)s AND date_joined = %(date_joined)s",
params={
"first_name": "Foo",
"is_staff": True,
"is_superuser": False,
"date_joined": datetime.datetime(2017, 12, 22, 16, 7, 1),
"date_joined": datetime.datetime(2017, 12, 22, 16, 7, 1), # noqa: DTZ001
},
)
)
Expand Down
6 changes: 4 additions & 2 deletions tests/panels/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def test_queryset_hook(self):
self.panel.templates[0]["context_list"],
[
"{'False': False, 'None': None, 'True': True}",
"{'deep_queryset': '<<triggers database query>>',\n"
" 'queryset': '<<queryset of auth.User>>'}",
(
"{'deep_queryset': '<<triggers database query>>',\n"
" 'queryset': '<<queryset of auth.User>>'}"
),
],
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def title(self):

@property
def content(self):
raise Exception
raise Exception # noqa: TRY002


@override_settings(DEBUG=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def title(self):

@property
def content(self):
raise Exception
raise Exception # noqa: TRY002


@override_settings(DEBUG=True)
Expand Down
Loading