From b82fc6418f929a9ddc5d867e5085b0abc90e07b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Wed, 30 Oct 2024 13:56:07 +0300 Subject: [PATCH 1/3] Update ruff's Python target-version value to 3.9 We no longer support Python 3.8 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 637fc0a16..32c78c93a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ packages = [ path = "debug_toolbar/__init__.py" [tool.ruff] -target-version = "py38" +target-version = "py39" fix = true show-fixes = true From 89f824a806af62e593dbfd7cd51ce2bf71af7648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Wed, 30 Oct 2024 13:57:47 +0300 Subject: [PATCH 2/3] Apply "import replacements" fixes from pyupgrade https://github.com/asottile/pyupgrade?tab=readme-ov-file#import-replacements --- debug_toolbar/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index 26154a736..dc3cc1adc 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -5,8 +5,9 @@ import os.path import sys import warnings +from collections.abc import Sequence from pprint import PrettyPrinter, pformat -from typing import Any, Sequence +from typing import Any from asgiref.local import Local from django.http import QueryDict From 2ce9e92760d73a2fc6698160e2223df8db02ab07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Wed, 30 Oct 2024 13:58:31 +0300 Subject: [PATCH 3/3] Apply "replace @functools.lru_cache(maxsize=None) with shorthand" fixes from pyupgrade https://github.com/asottile/pyupgrade?tab=readme-ov-file#replace-functoolslru_cachemaxsizenone-with-shorthand --- debug_toolbar/middleware.py | 4 ++-- debug_toolbar/panels/sql/utils.py | 4 ++-- debug_toolbar/settings.py | 6 +++--- debug_toolbar/toolbar.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 1bf9b4e70..9986d9106 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -4,7 +4,7 @@ import re import socket -from functools import lru_cache +from functools import cache from asgiref.sync import iscoroutinefunction, markcoroutinefunction from django.conf import settings @@ -46,7 +46,7 @@ def show_toolbar(request): return False -@lru_cache(maxsize=None) +@cache def get_show_toolbar(): # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended # setup, resolve it to the corresponding callable. diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py index b8fd34afe..305543aec 100644 --- a/debug_toolbar/panels/sql/utils.py +++ b/debug_toolbar/panels/sql/utils.py @@ -1,4 +1,4 @@ -from functools import lru_cache +from functools import cache, lru_cache from html import escape import sqlparse @@ -107,7 +107,7 @@ def parse_sql(sql, *, simplify=False): return "".join(stack.run(sql)) -@lru_cache(maxsize=None) +@cache def get_filter_stack(*, simplify): stack = sqlparse.engine.FilterStack() if simplify: diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 48483cf40..e0be35ea8 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -1,6 +1,6 @@ import sys import warnings -from functools import lru_cache +from functools import cache from django.conf import settings from django.dispatch import receiver @@ -49,7 +49,7 @@ } -@lru_cache(maxsize=None) +@cache def get_config(): USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {}) CONFIG = CONFIG_DEFAULTS.copy() @@ -75,7 +75,7 @@ def get_config(): ] -@lru_cache(maxsize=None) +@cache def get_panels(): try: PANELS = list(settings.DEBUG_TOOLBAR_PANELS) diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index edd5c369b..afb7affac 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -5,7 +5,7 @@ import re import uuid from collections import OrderedDict -from functools import lru_cache +from functools import cache from django.apps import apps from django.conf import settings @@ -180,7 +180,7 @@ def is_toolbar_request(cls, request): return resolver_match.namespaces and resolver_match.namespaces[-1] == APP_NAME @staticmethod - @lru_cache(maxsize=None) + @cache def get_observe_request(): # If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended # setup, resolve it to the corresponding callable.