Skip to content

Commit 32372b2

Browse files
committed
chore: use pre-commit configuration from Flask
1 parent f6cc1f5 commit 32372b2

37 files changed

+73
-106
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
---
21
repos:
3-
- repo: https://github.com/asottile/pyupgrade
4-
rev: v3.13.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.6.9
54
hooks:
6-
- id: pyupgrade
7-
args: ["--py39-plus"]
8-
- repo: https://github.com/asottile/reorder_python_imports
9-
rev: v3.11.0
10-
hooks:
11-
- id: reorder-python-imports
12-
args: ["--application-directories", "src"]
13-
- repo: https://github.com/psf/black
14-
rev: 23.9.1
15-
hooks:
16-
- id: black
17-
- repo: https://github.com/pycqa/flake8
18-
rev: 6.1.0
19-
hooks:
20-
- id: flake8
21-
additional_dependencies:
22-
- flake8-bugbear
23-
- flake8-implicit-str-concat
24-
- flake8-pyproject
5+
- id: ruff
6+
- id: ruff-format
257
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.4.0
8+
rev: v5.0.0
279
hooks:
28-
- id: check-byte-order-marker
10+
- id: check-merge-conflict
11+
- id: debug-statements
12+
- id: fix-byte-order-marker
2913
- id: trailing-whitespace
3014
- id: end-of-file-fixer

pyproject.toml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,22 @@ exclude_lines = [
7878
"pass",
7979
]
8080

81-
[tool.flake8]
82-
# B = bugbear
83-
# E = pycodestyle errors
84-
# F = flake8 pyflakes
85-
# W = pycodestyle warnings
86-
# B9 = bugbear opinions
87-
# ISC = implicit-str-concat
88-
select = ["B", "E", "F", "W", "B9", "ISC"]
89-
ignore = [
90-
# slice notation whitespace, invalid
91-
"E203",
92-
# line length, handled by bugbear B950
93-
"E501",
94-
# bare except, handled by bugbear B001
95-
"E722",
96-
# bin op line break, invalid
97-
"W503",
98-
# requires 'strict' argument for 'zip'
99-
# that needs python >= 3.10
100-
"B905",
101-
]
102-
# up to 88 allowed by bugbear B950
103-
max-line-length = 80
104-
per-file-ignores = [
105-
# __init__ modules export names
106-
"**/__init__.py: F401, F403",
81+
[tool.ruff]
82+
src = ["src"]
83+
fix = true
84+
show-fixes = true
85+
output-format = "full"
86+
87+
[tool.ruff.lint]
88+
select = [
89+
"B", # flake8-bugbear
90+
"E", # pycodestyle error
91+
"F", # pyflakes
92+
"I", # isort
93+
"UP", # pyupgrade
94+
"W", # pycodestyle warning
10795
]
96+
97+
[tool.ruff.lint.isort]
98+
force-single-line = true
99+
order-by-type = false

src/wtforms/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from wtforms.form import Form
3636
from wtforms.validators import ValidationError
3737

38-
3938
__version__ = "3.1.2"
4039

4140
__all__ = [

src/wtforms/csrf/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
validates with the hmac of the random value + expiration time, and the
1313
expiration time is not passed, the CSRF validation will pass.
1414
"""
15+
1516
import hmac
1617
import os
1718
from datetime import datetime

src/wtforms/fields/core.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ def check_validators(cls, validators):
181181
for validator in validators:
182182
if not callable(validator):
183183
raise TypeError(
184-
"{} is not a valid validator because it is not "
185-
"callable".format(validator)
184+
f"{validator} is not a valid validator because it is not "
185+
"callable"
186186
)
187187

188188
if inspect.isclass(validator):
189189
raise TypeError(
190-
"{} is not a valid validator because it is a class, "
191-
"it should be an instance".format(validator)
190+
f"{validator} is not a valid validator because it is a class, "
191+
"it should be an instance"
192192
)
193193

194194
def gettext(self, string):
@@ -399,8 +399,10 @@ def bind(self, form, name, prefix="", translations=None, **kwargs):
399399
return self.field_class(*self.args, **kw)
400400

401401
def __repr__(self):
402-
return "<UnboundField({}, {!r}, {!r})>".format(
403-
self.field_class.__name__, self.args, self.kwargs
402+
return (
403+
"<UnboundField("
404+
f"{self.field_class.__name__}, {self.args!r}, {self.kwargs!r}"
405+
")>"
404406
)
405407

406408

@@ -425,7 +427,8 @@ def __repr__(self):
425427
for name in dir(self)
426428
if not name.startswith("_")
427429
)
428-
return "<wtforms.fields.Flags: {%s}>" % ", ".join(flags)
430+
flags = ", ".join(flags)
431+
return f"<wtforms.fields.Flags: {{{flags}}}>"
429432

430433

431434
class Label:

src/wtforms/fields/form.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from wtforms.utils import unset_value
2+
13
from .. import widgets
24
from .core import Field
3-
from wtforms.utils import unset_value
45

56
__all__ = ("FormField",)
67

src/wtforms/fields/list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import itertools
22

3+
from wtforms.utils import unset_value
4+
35
from .. import widgets
46
from .core import Field
57
from .core import UnboundField
6-
from wtforms.utils import unset_value
78

89
__all__ = ("FieldList",)
910

src/wtforms/form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def process(self, formdata=None, obj=None, data=None, extra_filters=None, **kwar
113113
for name, field in self._fields.items():
114114
field_extra_filters = filters.get(name, [])
115115

116-
inline_filter = getattr(self, "filter_%s" % name, None)
116+
inline_filter = getattr(self, f"filter_{name}", None)
117117
if inline_filter is not None:
118118
field_extra_filters.append(inline_filter)
119119

src/wtforms/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22

3-
43
# https://docs.python.org/3/library/datetime.html#technical-detail (see NOTE #9)
54
_DATETIME_STRIP_ZERO_PADDING_FORMATS_RE = re.compile(
65
"%-["

src/wtforms/widgets/core.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __call__(self, field, **kwargs):
111111
html.append(f"<li>{subfield.label} {subfield()}</li>")
112112
else:
113113
html.append(f"<li>{subfield()} {subfield.label}</li>")
114-
html.append("</%s>" % self.html_tag)
114+
html.append(f"</{self.html_tag}>")
115115
return Markup("".join(html))
116116

117117

@@ -134,15 +134,15 @@ def __call__(self, field, **kwargs):
134134
html = []
135135
if self.with_table_tag:
136136
kwargs.setdefault("id", field.id)
137-
html.append("<table %s>" % html_params(**kwargs))
137+
table_params = html_params(**kwargs)
138+
html.append(f"<table {table_params}>")
138139
hidden = ""
139140
for subfield in field:
140141
if subfield.type in ("HiddenField", "CSRFTokenField"):
141142
hidden += str(subfield)
142143
else:
143144
html.append(
144-
"<tr><th>%s</th><td>%s%s</td></tr>"
145-
% (str(subfield.label), hidden, str(subfield))
145+
f"<tr><th>{subfield.label}</th><td>{hidden}{subfield}</td></tr>"
146146
)
147147
hidden = ""
148148
if self.with_table_tag:
@@ -178,7 +178,8 @@ def __call__(self, field, **kwargs):
178178
for k in dir(flags):
179179
if k in self.validation_attrs and k not in kwargs:
180180
kwargs[k] = getattr(flags, k)
181-
return Markup("<input %s>" % self.html_params(name=field.name, **kwargs))
181+
input_params = self.html_params(name=field.name, **kwargs)
182+
return Markup(f"<input {input_params}>")
182183

183184

184185
class TextInput(Input):
@@ -321,9 +322,10 @@ def __call__(self, field, **kwargs):
321322
for k in dir(flags):
322323
if k in self.validation_attrs and k not in kwargs:
323324
kwargs[k] = getattr(flags, k)
325+
textarea_params = html_params(name=field.name, **kwargs)
326+
textarea_innerhtml = escape(field._value())
324327
return Markup(
325-
"<textarea %s>\r\n%s</textarea>"
326-
% (html_params(name=field.name, **kwargs), escape(field._value()))
328+
f"<textarea {textarea_params}>\r\n{textarea_innerhtml}</textarea>"
327329
)
328330

329331

@@ -356,10 +358,12 @@ def __call__(self, field, **kwargs):
356358
for k in dir(flags):
357359
if k in self.validation_attrs and k not in kwargs:
358360
kwargs[k] = getattr(flags, k)
359-
html = ["<select %s>" % html_params(name=field.name, **kwargs)]
361+
select_params = html_params(name=field.name, **kwargs)
362+
html = [f"<select {select_params}>"]
360363
if field.has_groups():
361364
for group, choices in field.iter_groups():
362-
html.append("<optgroup %s>" % html_params(label=group))
365+
optgroup_params = html_params(label=group)
366+
html.append(f"<optgroup {optgroup_params}>")
363367
for choice in choices:
364368
if len(choice) == 4:
365369
val, label, selected, render_kw = choice

0 commit comments

Comments
 (0)