Skip to content

Commit ec91456

Browse files
committed
fixup! fixup! [WIP] pre-commit and ruff
1 parent d93cb58 commit ec91456

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+189
-140
lines changed

ruff.toml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ select = [
4141
"E",
4242
# https://docs.astral.sh/ruff/rules/#pyflakes-f
4343
"F",
44+
# https://docs.astral.sh/ruff/rules/#isort-i
45+
"I",
4446
]
4547
ignore = [
4648
# Whitespace before ':' (conflicts with Black)

src/open_inwoner/accounts/gateways.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def send(self, to, token, **kwargs):
6565
)
6666
except messagebird.client.ErrorException as e:
6767
for error in e.errors:
68-
logger.critical(f"Could not send SMS to {to}:\n{error}")
68+
logger.critical(
69+
("Could not send SMS to {to}:\n{error}").format(to=to, error=error)
70+
)
6971
raise GatewayError()
7072
else:
7173
logging.debug('Sent SMS to %s: "%s"', to, self.get_message(token))

src/open_inwoner/accounts/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_by_kvk(self, kvk):
3333

3434
def eherkenning_create(self, kvk, **kwargs):
3535
return super().create(
36-
email=f"user-{kvk}@localhost",
36+
email="user-{}@localhost".format(kvk),
3737
login_type=LoginTypeChoices.eherkenning,
3838
kvk=kvk,
3939
)

src/open_inwoner/accounts/models.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def get_callback_view(self):
110110

111111
def generate_uuid_image_name(instance, filename):
112112
filename, file_extension = os.path.splitext(filename)
113-
return f"profile/{uuid4()}{file_extension.lower()}"
113+
return "profile/{uuid}{file_extension}".format(
114+
uuid=uuid4(), file_extension=file_extension.lower()
115+
)
114116

115117

116118
class User(AbstractBaseUser, PermissionsMixin):
@@ -881,7 +883,7 @@ def get_full_name(self):
881883
"""
882884
Returns the first_name plus the last_name of the invitee, with a space in between.
883885
"""
884-
full_name = f"{self.invitee_first_name} {self.invitee_last_name}"
886+
full_name = "{} {}".format(self.invitee_first_name, self.invitee_last_name)
885887
return full_name.strip()
886888

887889
def save(self, **kwargs):

src/open_inwoner/accounts/notifications/tasks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from collections.abc import Callable
2-
from typing import Any
1+
from typing import Any, Callable
32

43
import celery
54

src/open_inwoner/accounts/tests/test_notify_expiring_actions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_send_emails_about_expiring_actions(self):
3030

3131
email1, email2 = mail.outbox
3232

33-
for email, recipient in zip([email1, email2], [joe, schmoe], strict=False):
33+
for email, recipient in zip([email1, email2], [joe, schmoe]):
3434
self.assertEqual(
3535
email.subject, "Acties verlopen vandaag op Open Inwoner Platform"
3636
)

src/open_inwoner/accounts/views/contactmoments.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
2-
from collections.abc import Iterable
3-
from typing import Protocol
2+
from typing import Iterable, Protocol
43

54
from django.contrib.auth.mixins import AccessMixin
65
from django.core.exceptions import ImproperlyConfigured

src/open_inwoner/accounts/views/login.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def form_valid(self, form):
8383
else:
8484
self.log_user_action(
8585
user,
86-
f"SMS bericht met code is verzonden aan {user.phonenumber}",
86+
"SMS bericht met code is verzonden aan {}".format(user.phonenumber),
8787
)
8888

8989
messages.debug(self.request, gateway.get_message(token))
@@ -255,7 +255,7 @@ def post(self, request):
255255
else:
256256
self.log_user_action(
257257
user,
258-
f"SMS bericht met code is verzonden aan {user.phonenumber}",
258+
"SMS bericht met code is verzonden aan {}".format(user.phonenumber),
259259
)
260260

261261
messages.debug(self.request, gateway.get_message(token))
@@ -333,7 +333,7 @@ def render_next_step(self, form, **kwargs):
333333

334334
self.log_user_action(
335335
self.user_cache,
336-
f"SMS bericht met code is verzonden aan {phonenumber}",
336+
"SMS bericht met code is verzonden aan {}".format(phonenumber),
337337
)
338338

339339
return super().render_next_step(form, **kwargs)
@@ -345,7 +345,7 @@ def done(self, form_list, **kwargs):
345345
self.request.user = self.user_cache
346346
self.log_change(
347347
self.user_cache,
348-
f"Telefoonnummer gewijzigd: {phonenumber}",
348+
"Telefoonnummer gewijzigd: {}".format(phonenumber),
349349
)
350350

351351
self.user_cache.save()

src/open_inwoner/cms/cases/views/cases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from collections.abc import Sequence
2+
from typing import Sequence
33

44
from django.urls import reverse
55
from django.utils.functional import cached_property

src/open_inwoner/cms/cases/views/services.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import enum
33
import functools
44
import logging
5-
from collections.abc import Callable
65
from dataclasses import dataclass
7-
from typing import TypedDict
6+
from typing import Callable, TypedDict
87

98
from django.http import HttpRequest
109
from django.utils.translation import gettext_lazy as _
@@ -226,7 +225,9 @@ def resolve_cases(
226225
case = futures[task]["case"]
227226
group = futures[task]["api_group"]
228227
logger.exception(
229-
f"Error while resolving case {case} with API group {group}"
228+
"Error while resolving case {case} with API group {group}".format(
229+
case=case, group=group
230+
)
230231
)
231232

232233
return resolved_cases
@@ -264,7 +265,7 @@ def resolve_case(self, case: Zaak, group: ZGWApiGroupConfig) -> Zaak:
264265
):
265266
try:
266267
update_case = task.result()
267-
if callable(update_case):
268+
if hasattr(update_case, "__call__"):
268269
update_case(case)
269270
except BaseException:
270271
logger.exception("Error in resolving case", stack_info=True)

src/open_inwoner/cms/cases/views/status.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import datetime as dt
33
import logging
44
from collections import defaultdict
5-
from collections.abc import Iterable
65
from datetime import datetime
7-
from typing import Protocol
6+
from typing import Iterable, Protocol
87

98
from django.conf import settings
109
from django.contrib import messages
@@ -317,7 +316,7 @@ def get_second_status_preview(self, statustypen: list) -> StatusType | None:
317316
# only 1 statustype for `self.case`
318317
# (this scenario is blocked by openzaak, but not part of the zgw standard)
319318
if len(statustype_numbers) < 2:
320-
logger.info(f"Case {self.case} has only one statustype")
319+
logger.info("Case {case} has only one statustype".format(case=self.case))
321320
return
322321

323322
statustype_numbers.sort()
@@ -367,7 +366,9 @@ def sync_statuses_with_status_types(
367366
# Workaround: OIP requests the current zaak.status individually and adds the retrieved information to the statustype mapping
368367

369368
logger.info(
370-
f"Issue #2037 -- Retrieving status individually for case {self.case.identification} because of eSuite"
369+
"Issue #2037 -- Retrieving status individually for case {} because of eSuite".format(
370+
self.case.identification
371+
)
371372
)
372373
self.case.status = zaken_client.fetch_single_status(self.case.status)
373374
status_types_mapping[self.case.status.statustype].append(self.case.status)
@@ -458,7 +459,9 @@ def is_file_upload_enabled_for_case_type(self) -> bool:
458459
).exists()
459460
)
460461
logger.info(
461-
f"Case {self.case.url} has case type file upload: {case_upload_enabled}"
462+
"Case {url} has case type file upload: {case_upload_enabled}".format(
463+
url=self.case.url, case_upload_enabled=case_upload_enabled
464+
)
462465
)
463466
return case_upload_enabled
464467

@@ -471,18 +474,26 @@ def is_file_upload_enabled_for_statustype(self) -> bool:
471474
except AttributeError as e:
472475
logger.exception(e)
473476
logger.info(
474-
f"Could not retrieve status type for case {self.case}; "
475-
"the status has not been resolved to a ZGW model object."
477+
"Could not retrieve status type for case {case}; "
478+
"the status has not been resolved to a ZGW model object.".format(
479+
case=self.case
480+
)
476481
)
477482
return True
478483
except KeyError as e:
479484
logger.exception(e)
480485
logger.info(
481-
f"Could not retrieve status type config for url {self.case.status.statustype.url}"
486+
"Could not retrieve status type config for url {url}".format(
487+
url=self.case.status.statustype.url
488+
)
482489
)
483490
return True
484491
logger.info(
485-
f"Case {self.case.url} status type {self.case.status.statustype} has status type file upload: {enabled_for_status_type}"
492+
"Case {url} status type {status_type} has status type file upload: {enabled_for_status_type}".format(
493+
url=self.case.url,
494+
status_type=self.case.status.statustype,
495+
enabled_for_status_type=enabled_for_status_type,
496+
)
486497
)
487498
return enabled_for_status_type
488499

@@ -652,9 +663,7 @@ def get_case_document_files(
652663

653664
config = OpenZaakConfig.get_solo()
654665
documents = []
655-
for case_info_obj, info_obj in zip(
656-
case_info_objects, info_objects, strict=False
657-
):
666+
for case_info_obj, info_obj in zip(case_info_objects, info_objects):
658667
if not info_obj:
659668
continue
660669
if not is_info_object_visible(

src/open_inwoner/components/templatetags/string_tags.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def optional_paragraph(optional_text: str) -> str:
2525
if not optional_text:
2626
return ""
2727
return format_html(
28-
f'<p class="utrecht-paragraph">{linebreaksbr(optional_text)}</p>'
28+
'<p class="utrecht-paragraph">{optional_text}</p>'.format(
29+
optional_text=linebreaksbr(optional_text)
30+
)
2931
)
3032

3133

src/open_inwoner/conf/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@
994994
)
995995

996996
if ALLOWED_HOSTS:
997-
BASE_URL = f"https://{ALLOWED_HOSTS[0]}"
997+
BASE_URL = "https://{}".format(ALLOWED_HOSTS[0])
998998
else:
999999
BASE_URL = "https://example.com"
10001000

src/open_inwoner/conf/local_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
PLAYWRIGHT_MULTI_ONLY_DEFAULT = True
1818

1919
# Enable django-debug-toolbar
20-
from .dev import INSTALLED_APPS, MIDDLEWARE # noqa: E402
20+
from .dev import INSTALLED_APPS, MIDDLEWARE
2121

2222
INSTALLED_APPS += ["debug_toolbar"]
2323
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]

src/open_inwoner/configurations/admin.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,14 @@ def report_contrast_ratio(self, request, obj):
339339
def check_contrast_ratio(label1, color1, label2, color2, expected_ratio):
340340
ratio = get_contrast_ratio(color1, color2)
341341
if ratio < expected_ratio:
342-
message = f"'{label1}' ({color1}) en '{label2}' ({color2}) hebben niet genoeg contrast: {round(ratio, 1)}:1 waar {expected_ratio}:1 wordt verwacht."
342+
message = "'{label1}' ({color1}) en '{label2}' ({color2}) hebben niet genoeg contrast: {ratio}:1 waar {expected}:1 wordt verwacht.".format(
343+
label1=label1,
344+
color1=color1,
345+
label2=label2,
346+
color2=color2,
347+
ratio=round(ratio, 1),
348+
expected=expected_ratio,
349+
)
343350
self.message_user(request, message, messages.WARNING)
344351

345352
check_contrast_ratio(

src/open_inwoner/configurations/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ class CustomFontSet(models.Model):
702702
def update_filename(self, filename: str, new_name: str, path: str) -> str:
703703
ext = filename.split(".")[1]
704704
filename = f"{new_name}.{ext}"
705-
return f"{path}/{filename}"
705+
return "{path}/{filename}".format(path=path, filename=filename)
706706

707707
def update_filename_body(self, filename: str) -> str:
708708
return CustomFontSet.update_filename(

src/open_inwoner/openklant/api_models.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dataclasses
22
from dataclasses import dataclass
33
from datetime import datetime
4-
from typing import NotRequired, TypedDict
4+
from typing import NotRequired, Optional, TypedDict, Union
55

66
from zgw_consumers.api_models.base import ZGWModel
77

@@ -63,11 +63,11 @@ class ContactMoment(ZGWModel):
6363
# eSuite OAS (compatible)
6464
url: str
6565
bronorganisatie: str
66-
registratiedatum: datetime | None = None
66+
registratiedatum: Optional[datetime] = None
6767
kanaal: str = ""
6868
tekst: str = ""
6969
# NOTE annoyingly we can't put MedewerkerIdentificatie here as type because of
70-
medewerker_identificatie: dict | None = None
70+
medewerker_identificatie: Optional[dict] = None
7171

7272
# modification to API for eSuite usefulness *AFWIJKING*
7373
identificatie: str = ""
@@ -79,8 +79,8 @@ class ContactMoment(ZGWModel):
7979
# open-klant OAS
8080
voorkeurskanaal: str = ""
8181
voorkeurstaal: str = ""
82-
vorig_contactmoment: str | None = None
83-
volgend_contactmoment: str | None = None
82+
vorig_contactmoment: Optional[str] = None
83+
volgend_contactmoment: Optional[str] = None
8484
onderwerp_links: list[str] = dataclasses.field(default_factory=list)
8585

8686
initiatiefnemer: str = ""
@@ -124,8 +124,8 @@ class KlantContactMoment(ZGWModel):
124124

125125
# eSuite OAS (compatible)
126126
url: str
127-
contactmoment: str | ContactMoment
128-
klant: str | Klant
127+
contactmoment: Union[str, ContactMoment]
128+
klant: Union[str, Klant]
129129
rol: str
130130

131131
# open-klant non-standard *AFWIJKING*
@@ -138,6 +138,6 @@ class ObjectContactMoment(ZGWModel):
138138
Contactmomenten API
139139
"""
140140

141-
contactmoment: str | ContactMoment
142-
object: str | Klant
141+
contactmoment: Union[str, ContactMoment]
142+
object: Union[str, Klant]
143143
object_type: str

src/open_inwoner/openklant/services.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import datetime
22
import logging
33
import uuid
4-
from collections.abc import Iterable
54
from datetime import timedelta
6-
from typing import Literal, NotRequired, Protocol, Self
5+
from typing import Iterable, Literal, NotRequired, Protocol, Self
76

87
import glom
98
from ape_pie.client import APIClient

src/open_inwoner/openklant/tests/test_openklant2_service.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ def test_update_partij_from_user(self):
304304
)
305305

306306

307-
QUESTION_DATE = datetime.datetime(2024, 10, 2, 14, 0, 25, 587564, tzinfo=datetime.UTC)
307+
QUESTION_DATE = datetime.datetime(
308+
2024, 10, 2, 14, 0, 25, 587564, tzinfo=datetime.timezone.utc
309+
)
308310

309311

310312
@tag("openklant2")

0 commit comments

Comments
 (0)