From d51dce7440b18d749928d93f2cdc36a7b1380ee2 Mon Sep 17 00:00:00 2001 From: Sidney Richards Date: Tue, 7 Jan 2025 13:51:17 +0100 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! [WIP] pre-commit and ruff --- .pre-commit-config.yaml | 11 ++++++- .../accounts/notifications/typing.py | 3 +- src/open_inwoner/accounts/tests/test_auth.py | 30 +++++++++---------- src/open_inwoner/cms/cases/forms.py | 6 ++-- src/open_inwoner/cms/cases/views/status.py | 6 ++-- src/open_inwoner/cms/extensions/cms_menus.py | 3 +- .../components/templatetags/action_tags.py | 6 ++-- .../configurations/bootstrap/cms.py | 3 +- .../configurations/bootstrap/siteconfig.py | 3 +- src/open_inwoner/openklant/services.py | 18 +++++------ src/open_inwoner/openzaak/admin.py | 12 ++++---- .../test_notification_zaak_infoobject.py | 6 ++-- src/open_inwoner/openzaak/types.py | 3 +- src/open_inwoner/pdc/managers.py | 6 ++-- src/open_inwoner/utils/validators.py | 3 +- 15 files changed, 65 insertions(+), 54 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 154fdc1908..e179429ddc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,4 +16,13 @@ repos: - id: ruff args: [--fix] # Run the formatter. - - id: ruff-format + # - id: ruff-format + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 22.12.0 + hooks: + - id: black + language_version: python3.11 diff --git a/src/open_inwoner/accounts/notifications/typing.py b/src/open_inwoner/accounts/notifications/typing.py index a54a78552e..23dfa92ac6 100644 --- a/src/open_inwoner/accounts/notifications/typing.py +++ b/src/open_inwoner/accounts/notifications/typing.py @@ -4,4 +4,5 @@ class Notifier(typing.Protocol): - def __call__(self, receiver: User, object_ids: list[int], channel: str) -> None: ... + def __call__(self, receiver: User, object_ids: list[int], channel: str) -> None: + ... diff --git a/src/open_inwoner/accounts/tests/test_auth.py b/src/open_inwoner/accounts/tests/test_auth.py index 2c4680e3b9..ddaa9c711c 100644 --- a/src/open_inwoner/accounts/tests/test_auth.py +++ b/src/open_inwoner/accounts/tests/test_auth.py @@ -152,9 +152,9 @@ def test_digid_fail_with_invite_redirects_to_register_page(self, m): m.return_value = True invite = InviteFactory() session = self.client.session - session["invite_url"] = ( - f"{reverse('django_registration_register')}?invite={invite.key}" - ) + session[ + "invite_url" + ] = f"{reverse('django_registration_register')}?invite={invite.key}" session.save() url = reverse("digid-mock:password") @@ -179,9 +179,9 @@ def test_digid_fail_with_invite_redirects_to_register_page(self, m): def test_invite_url_not_in_session_after_successful_login(self): invite = InviteFactory() session = self.client.session - session["invite_url"] = ( - f"{reverse('django_registration_register')}?invite={invite.key}" - ) + session[ + "invite_url" + ] = f"{reverse('django_registration_register')}?invite={invite.key}" session.save() url = reverse("digid-mock:password") @@ -283,9 +283,9 @@ def test_notification_settings_with_cms_page_published(self, m): self.assertNotIn("messages_notifications", necessary_form.fields) necessary_form["plans_notifications"] = False - necessary_form["case_notification_channel"] = ( - NotificationChannelChoice.digital_only - ) + necessary_form[ + "case_notification_channel" + ] = NotificationChannelChoice.digital_only necessary_form.submit() user = User.objects.get(bsn=data["auth_name"]) @@ -668,9 +668,9 @@ def test_eherkenning_fail_with_invite_redirects_to_register_page(self, m): m.return_value = True invite = InviteFactory() session = self.client.session - session["invite_url"] = ( - f"{reverse('django_registration_register')}?invite={invite.key}" - ) + session[ + "invite_url" + ] = f"{reverse('django_registration_register')}?invite={invite.key}" session.save() url = reverse("eherkenning-mock:password") @@ -722,9 +722,9 @@ def test_invite_url_not_in_session_after_successful_login( invite = InviteFactory() session = self.client.session - session["invite_url"] = ( - f"{reverse('django_registration_register')}?invite={invite.key}" - ) + session[ + "invite_url" + ] = f"{reverse('django_registration_register')}?invite={invite.key}" session.save() url = reverse("eherkenning-mock:password") diff --git a/src/open_inwoner/cms/cases/forms.py b/src/open_inwoner/cms/cases/forms.py index c8988759c1..f21ac5a228 100644 --- a/src/open_inwoner/cms/cases/forms.py +++ b/src/open_inwoner/cms/cases/forms.py @@ -37,10 +37,8 @@ def __init__(self, case, **kwargs): if case: self.fields[ "type" - ].queryset = ( - ZaakTypeInformatieObjectTypeConfig.objects.filter_enabled_for_case_type( - case.zaaktype - ) + ].queryset = ZaakTypeInformatieObjectTypeConfig.objects.filter_enabled_for_case_type( + case.zaaktype ) choices = self.fields["type"].choices diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index b35bddef71..436801886e 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -911,9 +911,9 @@ def post(self, request, *args, **kwargs): send_confirmation = False if config.register_email: - form.cleaned_data["question"] += ( - f"\n\nCase number: {self.case.identificatie}" - ) + form.cleaned_data[ + "question" + ] += f"\n\nCase number: {self.case.identificatie}" email_success = self.register_by_email(form, config.register_email) send_confirmation = email_success diff --git a/src/open_inwoner/cms/extensions/cms_menus.py b/src/open_inwoner/cms/extensions/cms_menus.py index 6ea41c4b75..7a2f71853e 100644 --- a/src/open_inwoner/cms/extensions/cms_menus.py +++ b/src/open_inwoner/cms/extensions/cms_menus.py @@ -35,8 +35,7 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): pages = ( Page.objects.filter(id__in=page_nodes.keys()) # optimise and only retrieve id and related object - .only("id") - .select_related("commonextension") + .only("id").select_related("commonextension") ) num_indicators = 0 diff --git a/src/open_inwoner/components/templatetags/action_tags.py b/src/open_inwoner/components/templatetags/action_tags.py index 4892e01e28..83e83cf5f3 100644 --- a/src/open_inwoner/components/templatetags/action_tags.py +++ b/src/open_inwoner/components/templatetags/action_tags.py @@ -80,9 +80,9 @@ def action_status_button(action, request, plan=None, **kwargs): for value, label, icon in StatusChoices.choices_with_icons() ] - kwargs["class"] = ( - f"actions__status-selector actions__status-selector--{action.status}" - ) + kwargs[ + "class" + ] = f"actions__status-selector actions__status-selector--{action.status}" kwargs.update( action=action, request=request, diff --git a/src/open_inwoner/configurations/bootstrap/cms.py b/src/open_inwoner/configurations/bootstrap/cms.py index 78022e70f8..4685c47fb3 100644 --- a/src/open_inwoner/configurations/bootstrap/cms.py +++ b/src/open_inwoner/configurations/bootstrap/cms.py @@ -60,7 +60,8 @@ def configure(self): cms_tools.create_apphook_page(self.app_hook, extension_args=extension_args) - def test_configuration(self): ... + def test_configuration(self): + ... class CMSConfigSettings(ConfigSettings): diff --git a/src/open_inwoner/configurations/bootstrap/siteconfig.py b/src/open_inwoner/configurations/bootstrap/siteconfig.py index 40dc40203b..123676ff61 100644 --- a/src/open_inwoner/configurations/bootstrap/siteconfig.py +++ b/src/open_inwoner/configurations/bootstrap/siteconfig.py @@ -149,4 +149,5 @@ def configure(self): form.save() - def test_configuration(self): ... + def test_configuration(self): + ... diff --git a/src/open_inwoner/openklant/services.py b/src/open_inwoner/openklant/services.py index 0badc29f95..f6764b6e4a 100644 --- a/src/open_inwoner/openklant/services.py +++ b/src/open_inwoner/openklant/services.py @@ -305,18 +305,18 @@ def update_user_from_klant(self, klant: Klant, user: User): and user.case_notification_channel != NotificationChannelChoice.digital_only ): - update_data["case_notification_channel"] = ( - NotificationChannelChoice.digital_only - ) + update_data[ + "case_notification_channel" + ] = NotificationChannelChoice.digital_only elif ( klant.toestemming_zaak_notificaties_alleen_digitaal is False and user.case_notification_channel != NotificationChannelChoice.digital_and_post ): - update_data["case_notification_channel"] = ( - NotificationChannelChoice.digital_and_post - ) + update_data[ + "case_notification_channel" + ] = NotificationChannelChoice.digital_and_post else: # This is a guard against the scenario where a deployment is # configured to use an older version of the klanten backend (that @@ -1252,9 +1252,9 @@ def questions_for_partij(self, partij_uuid: str) -> list[OpenKlant2Question]: for klantcontact in self.klantcontacten_for_partij( partij_uuid, kanaal=self.config.mijn_vragen_kanaal ): - klantcontact_uuid_to_klantcontact_object[klantcontact["uuid"]] = ( - klantcontact - ) + klantcontact_uuid_to_klantcontact_object[ + klantcontact["uuid"] + ] = klantcontact # A klantcontact is an answer if it is linked to a Question via an onderwerp object if onderwerp_objecten := klantcontact["gingOverOnderwerpobjecten"]: diff --git a/src/open_inwoner/openzaak/admin.py b/src/open_inwoner/openzaak/admin.py index d1bfc6cb7f..d67ca145d8 100644 --- a/src/open_inwoner/openzaak/admin.py +++ b/src/open_inwoner/openzaak/admin.py @@ -145,9 +145,9 @@ def export_catalogus_configs(modeladmin, request, queryset): export.as_jsonl_iter(), content_type="application/json", ) - response["Content-Disposition"] = ( - 'attachment; filename="zgw-catalogi-export.json"' - ) + response[ + "Content-Disposition" + ] = 'attachment; filename="zgw-catalogi-export.json"' return response def process_file_view(self, request): @@ -453,9 +453,9 @@ def export_zaaktype_configs(modeladmin, request, queryset): export.as_jsonl_iter(), content_type="application/json", ) - response["Content-Disposition"] = ( - 'attachment; filename="zgw-zaaktype-export.json"' - ) + response[ + "Content-Disposition" + ] = 'attachment; filename="zgw-zaaktype-export.json"' return response def process_file_view(self, request): diff --git a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py index 40c8dbb897..ac148e0d41 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py +++ b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py @@ -292,9 +292,9 @@ def test_zio_bails_when_info_object_not_visible_because_confidentiality( self, m, mock_handle: Mock ): data = MockAPIData() - data.informatie_object["vertrouwelijkheidaanduiding"] = ( - VertrouwelijkheidsAanduidingen.geheim - ) + data.informatie_object[ + "vertrouwelijkheidaanduiding" + ] = VertrouwelijkheidsAanduidingen.geheim data.install_mocks(m) handle_zaken_notification(data.zio_notification) diff --git a/src/open_inwoner/openzaak/types.py b/src/open_inwoner/openzaak/types.py index bbb3102567..ccecb11a7a 100644 --- a/src/open_inwoner/openzaak/types.py +++ b/src/open_inwoner/openzaak/types.py @@ -9,7 +9,8 @@ class UniformCase(Protocol): """ @property - def identification(self) -> str: ... + def identification(self) -> str: + ... def process_data(self) -> dict: """ diff --git a/src/open_inwoner/pdc/managers.py b/src/open_inwoner/pdc/managers.py index 48390665be..ac0bf8a4d4 100644 --- a/src/open_inwoner/pdc/managers.py +++ b/src/open_inwoner/pdc/managers.py @@ -93,9 +93,9 @@ def filter_by_zaken(self, cases: list[Zaak]): or months_since_last_zaak_per_zaaktype[zaaktype_identificatie] > duration_since_start.months ): - months_since_last_zaak_per_zaaktype[zaaktype_identificatie] = ( - duration_since_start.months - ) + months_since_last_zaak_per_zaaktype[ + zaaktype_identificatie + ] = duration_since_start.months zaaktype_ids = list(months_since_last_zaak_per_zaaktype.keys()) diff --git a/src/open_inwoner/utils/validators.py b/src/open_inwoner/utils/validators.py index c7a0aa739b..a651a63c72 100644 --- a/src/open_inwoner/utils/validators.py +++ b/src/open_inwoner/utils/validators.py @@ -14,7 +14,8 @@ class ParsePhoneNumber(Protocol): - def __call__(self, value: str) -> "PhoneNumber": ... # pragma: nocover + def __call__(self, value: str) -> "PhoneNumber": + ... # pragma: nocover @deconstructible