From 2b43792210573af907a9ea389d1f008523774ce2 Mon Sep 17 00:00:00 2001 From: Sidney Richards Date: Mon, 10 Feb 2025 22:59:01 +0100 Subject: [PATCH] Apply the ruff FURB rule --- .../accounts/tests/test_profile_views.py | 7 +------ src/open_inwoner/cms/cases/views/services.py | 20 +++++++++--------- src/open_inwoner/plans/views.py | 6 +++--- src/open_inwoner/questionnaire/views.py | 10 ++++----- src/open_inwoner/ssd/forms.py | 6 +----- src/open_inwoner/ssd/xml.py | 21 +++++++------------ 6 files changed, 27 insertions(+), 43 deletions(-) diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index 36e117e286..87e4d6fbb9 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -880,12 +880,7 @@ def assertDataDisplays(self, response): s = elem.text.strip() texts.add(s) - missing = list() - for s in self.expected_strings: - if s not in texts: - missing.append(s) - - if missing: + if missing := [s for s in self.expected_strings if s not in texts]: f = ", ".join(f"'{s}'" for s in missing) self.fail(f"missing display of values: {f}") diff --git a/src/open_inwoner/cms/cases/views/services.py b/src/open_inwoner/cms/cases/views/services.py index 75c5dbfc81..720136179b 100644 --- a/src/open_inwoner/cms/cases/views/services.py +++ b/src/open_inwoner/cms/cases/views/services.py @@ -125,12 +125,11 @@ def get_submissions(self) -> list[SubmissionWithApiGroup]: for task in concurrent.futures.as_completed(futures): try: group_for_task = all_api_groups[futures.index(task)] - for row in task.result(): - subs_with_api_group.append( - SubmissionWithApiGroup( - submission=row, api_group=group_for_task - ) - ) + subs_with_api_group.extend( + SubmissionWithApiGroup(submission=row, api_group=group_for_task) + for row in task.result() + ) + except BaseException: logger.exception("Error fetching and pre-processing cases") @@ -177,10 +176,11 @@ def get_cases(self) -> list[ZaakWithApiGroup]: ): group_for_task = all_api_groups[futures.index(task)] try: - for row in task.result(): - cases_with_api_group.append( - ZaakWithApiGroup(zaak=row, api_group=group_for_task) - ) + cases_with_api_group.extend( + ZaakWithApiGroup(zaak=row, api_group=group_for_task) + for row in task.result() + ) + except BaseException: logger.exception( "Error while fetching and pre-processing cases for API group %s", diff --git a/src/open_inwoner/plans/views.py b/src/open_inwoner/plans/views.py index 9dd5d8b811..a8fe1d7c00 100644 --- a/src/open_inwoner/plans/views.py +++ b/src/open_inwoner/plans/views.py @@ -118,9 +118,9 @@ def get_available_contacts_for_filtering(self, plans): """ Return all available contacts for filtering for all the plans. """ - user_contacts_qs = [] - for plan in plans: - user_contacts_qs.append(plan.get_other_users(user=self.request.user)) + user_contacts_qs = ( + plan.get_other_users(user=self.request.user) for plan in plans + ) available_contacts = User.objects.none() for qs in user_contacts_qs: diff --git a/src/open_inwoner/questionnaire/views.py b/src/open_inwoner/questionnaire/views.py index cdaec76107..4c68141a91 100644 --- a/src/open_inwoner/questionnaire/views.py +++ b/src/open_inwoner/questionnaire/views.py @@ -119,11 +119,11 @@ def get_context_data(self, **kwargs: Any) -> dict[str, Any]: content = [c.content for c in tree] root_title = tree.first().title - steps = [] - for i in range(len(answers)): - steps.append( - {"question": questions[i], "answer": answers[i], "content": content[i]} - ) + steps = [ + {"question": questions[i], "answer": answer, "content": content[i]} + for i, answer in enumerate(answers) + ] + last_step = tree.last() context["root_title"] = root_title diff --git a/src/open_inwoner/ssd/forms.py b/src/open_inwoner/ssd/forms.py index a59773736f..9c59b857bf 100644 --- a/src/open_inwoner/ssd/forms.py +++ b/src/open_inwoner/ssd/forms.py @@ -61,11 +61,7 @@ def get_yearly_report_dates() -> list[tuple[date, str]]: if today < available_from: dates.pop(0) - choices = [] - for report_date in dates: - choices.append((report_date.date(), str(report_date.year))) - - return choices + return [(report_date.date(), str(report_date.year)) for report_date in dates] # diff --git a/src/open_inwoner/ssd/xml.py b/src/open_inwoner/ssd/xml.py index e1a7fa76d3..5a50362f2a 100644 --- a/src/open_inwoner/ssd/xml.py +++ b/src/open_inwoner/ssd/xml.py @@ -80,16 +80,13 @@ def get_jaaropgaven(response: requests.Response) -> list[dict] | None: except AttributeError: return None - jaaropgaven = [] - for specificatie in specificatien: - jaaropgaven.append( - { + return [{ "client": client, "inhoudingsplichtige": inhoudingsplichtige, "specificatie": specificatie, - } - ) - return jaaropgaven + } for specificatie in specificatien] + + def get_uitkeringen(response: requests.Response) -> list[dict] | None: @@ -114,14 +111,10 @@ def get_uitkeringen(response: requests.Response) -> list[dict] | None: except AttributeError: return None - uitkeringen = [] - for historie in dossierhistorien: - uitkeringen.append( - { + return [ + { "uitkeringsinstantie": uitkeringsinstantie, "client": client, "dossierhistorie": historie, "details": historie.componenthistorie, - } - ) - return uitkeringen + } for historie in dossierhistorien]