Skip to content

Commit

Permalink
Update pyupgrade's target version to Python 3.9 (#2024)
Browse files Browse the repository at this point in the history
* Update ruff's Python target-version value to 3.9

We no longer support Python 3.8

* Apply "import replacements" fixes from pyupgrade

https://github.com/asottile/pyupgrade?tab=readme-ov-file#import-replacements

* 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
  • Loading branch information
ulgens authored Oct 31, 2024
1 parent 396b626 commit fc4bf66
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/panels/sql/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from functools import lru_cache
from functools import cache, lru_cache
from html import escape

import sqlparse
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,7 +49,7 @@
}


@lru_cache(maxsize=None)
@cache
def get_config():
USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
CONFIG = CONFIG_DEFAULTS.copy()
Expand All @@ -75,7 +75,7 @@ def get_config():
]


@lru_cache(maxsize=None)
@cache
def get_panels():
try:
PANELS = list(settings.DEBUG_TOOLBAR_PANELS)
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion debug_toolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ packages = [
path = "debug_toolbar/__init__.py"

[tool.ruff]
target-version = "py38"
target-version = "py39"

fix = true
show-fixes = true
Expand Down

0 comments on commit fc4bf66

Please sign in to comment.