Skip to content

Commit 904f2eb

Browse files
committed
Activate more ruff rules
1 parent 3b87b93 commit 904f2eb

File tree

12 files changed

+80
-31
lines changed

12 files changed

+80
-31
lines changed

debug_toolbar/forms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def clean_signed(self):
3838
signing.Signer(salt=self.salt).unsign(self.cleaned_data["signed"])
3939
)
4040
return verified
41-
except signing.BadSignature:
42-
raise ValidationError("Bad signature")
41+
except signing.BadSignature as exc:
42+
raise ValidationError("Bad signature") from exc
4343

4444
def verified_data(self):
4545
return self.is_valid() and self.cleaned_data["signed"]

debug_toolbar/panels/headers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HeadersPanel(Panel):
3333
template = "debug_toolbar/panels/headers.html"
3434

3535
def process_request(self, request):
36-
wsgi_env = list(sorted(request.META.items()))
36+
wsgi_env = sorted(request.META.items())
3737
self.request_headers = {
3838
unmangle(k): v for (k, v) in wsgi_env if is_http_header(k)
3939
}

debug_toolbar/panels/history/panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class HistoryPanel(Panel):
2222
def get_headers(self, request):
2323
headers = super().get_headers(request)
2424
observe_request = self.toolbar.get_observe_request()
25-
store_id = getattr(self.toolbar, "store_id")
25+
store_id = self.toolbar.store_id
2626
if store_id and observe_request(request):
2727
headers["djdt-store-id"] = store_id
2828
return headers

debug_toolbar/panels/profiling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class FunctionCall:
1515
def __init__(
16-
self, statobj, func, depth=0, stats=None, id=0, parent_ids=[], hsv=(0, 0.5, 1)
16+
self, statobj, func, depth=0, stats=None, id=0, parent_ids=None, hsv=(0, 0.5, 1)
1717
):
1818
self.statobj = statobj
1919
self.func = func
@@ -23,7 +23,7 @@ def __init__(
2323
self.stats = statobj.stats[func][:4]
2424
self.depth = depth
2525
self.id = id
26-
self.parent_ids = parent_ids
26+
self.parent_ids = parent_ids or []
2727
self.hsv = hsv
2828

2929
def parent_classes(self):

debug_toolbar/panels/sql/forms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def clean_params(self):
3737

3838
try:
3939
return json.loads(value)
40-
except ValueError:
41-
raise ValidationError("Is not valid JSON")
40+
except ValueError as exc:
41+
raise ValidationError("Is not valid JSON") from exc
4242

4343
def clean_alias(self):
4444
value = self.cleaned_data["alias"]

debug_toolbar/panels/sql/panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _duplicate_query_key(query):
9090

9191
def _process_query_groups(query_groups, databases, colors, name):
9292
counts = defaultdict(int)
93-
for (alias, key), query_group in query_groups.items():
93+
for (alias, _key), query_group in query_groups.items():
9494
count = len(query_group)
9595
# Queries are similar / duplicates only if there are at least 2 of them.
9696
if count > 1:

debug_toolbar/panels/templates/panel.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ def generate_stats(self, request, response):
192192
template = self.templates[0]["template"]
193193
# django templates have the 'engine' attribute, while jinja
194194
# templates use 'backend'
195-
engine_backend = getattr(template, "engine", None) or getattr(
196-
template, "backend"
197-
)
195+
engine_backend = getattr(template, "engine", None) or template.backend
198196
template_dirs = engine_backend.dirs
199197
else:
200198
context_processors = None

debug_toolbar/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def get_panels():
8383
warnings.warn(
8484
f"Please remove {logging_panel} from your DEBUG_TOOLBAR_PANELS setting.",
8585
DeprecationWarning,
86+
stacklevel=1,
8687
)
8788
return PANELS
8889

debug_toolbar/toolbar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def render_toolbar(self):
8686
"The debug toolbar requires the staticfiles contrib app. "
8787
"Add 'django.contrib.staticfiles' to INSTALLED_APPS and "
8888
"define STATIC_URL in your settings."
89-
)
89+
) from None
9090
else:
9191
raise
9292

pyproject.toml

+58-17
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,65 @@ source = ["src", ".tox/*/site-packages"]
6666
fail_under = 94
6767
show_missing = true
6868

69-
[tool.ruff.isort]
70-
combine-as-imports = true
71-
7269
[tool.ruff]
73-
select = [
74-
# flake8/Pyflakes
75-
"F",
76-
# flake8/pycodestyle
77-
"E",
78-
"W",
79-
# isort
80-
"I",
81-
# pyupgrade
82-
"UP",
83-
# pygrep-hooks
84-
"PGH",
70+
extend-select = [
71+
# pyflakes, pycodestyle
72+
"F", "E", "W",
73+
# mmcabe
74+
# "C90",
75+
# isort
76+
"I",
77+
# pep8-naming
78+
# "N",
79+
# pyupgrade
80+
"UP",
81+
# flake8-2020
82+
# "YTT",
83+
# flake8-boolean-trap
84+
# "FBT",
85+
# flake8-bugbear
86+
"B",
87+
# flake8-builtins
88+
# "A",
89+
# flake8-comprehensions
90+
"C4",
91+
# flake8-django
92+
"DJ",
93+
# flake8-logging-format
94+
"G",
95+
# flake8-pie
96+
# "PIE",
97+
# flake8-simplify
98+
# "SIM",
99+
# flake8-gettext
100+
"INT",
101+
# pygrep-hooks
102+
"PGH",
103+
# pylint
104+
# "PL",
105+
# unused noqa
106+
"RUF100",
85107
]
86-
ignore = [
87-
"E501",
108+
extend-ignore = [
109+
# Allow zip() without strict=
110+
"B905",
111+
# No line length errors
112+
"E501",
88113
]
114+
fix = true
115+
show-fixes = true
89116
target-version = "py38"
117+
118+
[tool.ruff.isort]
119+
combine-as-imports = true
120+
121+
[tool.ruff.mccabe]
122+
max-complexity = 15
123+
124+
[tool.ruff.per-file-ignores]
125+
"*/migrat*/*" = [
126+
# Allow using PascalCase model names in migrations
127+
"N806",
128+
# Ignore the fact that migration files are invalid module names
129+
"N999",
130+
]

tests/context_processors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
def broken(request):
2-
request.non_existing_attribute
2+
_read = request.non_existing_attribute

tests/models.py

+9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ def __repr__(self):
1111
class Binary(models.Model):
1212
field = models.BinaryField()
1313

14+
def __str__(self):
15+
return ""
16+
1417

1518
class PostgresJSON(models.Model):
1619
field = JSONField()
1720

21+
def __str__(self):
22+
return ""
23+
1824

1925
if settings.USE_GIS:
2026
from django.contrib.gis.db import models as gismodels
2127

2228
class Location(gismodels.Model):
2329
point = gismodels.PointField()
30+
31+
def __str__(self):
32+
return ""

0 commit comments

Comments
 (0)