From a344bd5cc179c1f732e20c1b639a9cd96707b62a Mon Sep 17 00:00:00 2001 From: Charles Beauville Date: Wed, 6 Dec 2023 15:35:02 +0100 Subject: [PATCH] Use walrus operator --- src/py/flwr_tool/update_changelog.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/py/flwr_tool/update_changelog.py b/src/py/flwr_tool/update_changelog.py index 47792ce5d5f5..8b0f9c866f58 100644 --- a/src/py/flwr_tool/update_changelog.py +++ b/src/py/flwr_tool/update_changelog.py @@ -158,8 +158,11 @@ def _update_entry( content, category_title, pr_info, unreleased_index, next_header_index ): """Update a specific section in the changelog content.""" - section_index = content.find(category_title, unreleased_index, next_header_index) - if section_index != -1: + if ( + section_index := content.find( + category_title, unreleased_index, next_header_index + ) + ) != -1: newline_index = content.find("\n", section_index) closing_parenthesis_index = content.rfind(")", unreleased_index, newline_index) updated_entry = f", [{pr_info.number}]({pr_info.html_url})" @@ -179,8 +182,7 @@ def _update_entry( def _insert_new_entry(content, pr_info, pr_reference, pr_entry_text, unreleased_index): """Insert a new entry into the changelog.""" - existing_entry_start = content.find(pr_entry_text) - if existing_entry_start != -1: + if (existing_entry_start := content.find(pr_entry_text)) != -1: pr_ref_end = content.rfind("\n", 0, existing_entry_start) updated_entry = ( f"{content[pr_ref_end]}\n, [{pr_info.number}]({pr_info.html_url})"