From 754d7e51081f625ca0604eddc3211a4cd4b7b03b Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 28 Jan 2026 16:38:48 +0100 Subject: [PATCH] transfer_missing_yaml_comments: Remove obsolete parameter fully_missing_only --- src/serena/config/serena_config.py | 2 +- src/serena/util/yaml.py | 32 ++++++++++-------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/serena/config/serena_config.py b/src/serena/config/serena_config.py index 03dd6abf..e746cafb 100644 --- a/src/serena/config/serena_config.py +++ b/src/serena/config/serena_config.py @@ -786,7 +786,7 @@ class SerenaConfig(ToolInclusionDefinition, ModeSelectionDefinition, ToStringMix # so we apply a conversion, which detects the old style and transforms it. normalise_yaml_comments(commented_yaml, YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING) template_yaml = load_yaml(SERENA_CONFIG_TEMPLATE_FILE, comment_normalisation=YamlCommentNormalisation.LEADING) - transfer_missing_yaml_comments(template_yaml, commented_yaml, YamlCommentNormalisation.LEADING, fully_missing_only=False) + transfer_missing_yaml_comments(template_yaml, commented_yaml, YamlCommentNormalisation.LEADING) save_yaml(self.config_file_path, commented_yaml) diff --git a/src/serena/util/yaml.py b/src/serena/util/yaml.py index a9e6ca7c..bb6bd290 100644 --- a/src/serena/util/yaml.py +++ b/src/serena/util/yaml.py @@ -201,14 +201,11 @@ def yaml_comment_entry_is_empty(comment_entry: Any) -> bool: return False -def transfer_missing_yaml_comments_by_index( - source: CommentedMap, target: CommentedMap, indices: list[int], fully_missing_only: bool = False -) -> None: +def transfer_missing_yaml_comments_by_index(source: CommentedMap, target: CommentedMap, indices: list[int]) -> None: """ :param source: the source, from which to transfer missing comments :param target: the target map, whose comments will be updated :param indices: list of comment indices to transfer - :param fully_missing_only: if True, only transfer comments for keys that have no comment definition at all (newly added) """ for key in target.keys(): if key in source: @@ -216,35 +213,28 @@ def transfer_missing_yaml_comments_by_index( if source_comment is None: continue target_comment = target.ca.items.get(key) - if target_comment is None and fully_missing_only: - # transfer full comment and we're done - target.ca.items[key] = source_comment - else: - # initialise target comment if needed - if target_comment is None: - target_comment = [None] * 4 - target.ca.items[key] = target_comment - # transfer missing comments at specified indices - for index in indices: - if yaml_comment_entry_is_empty(target_comment[index]): - target_comment[index] = source_comment[index] + # initialise target comment if needed + if target_comment is None: + target_comment = [None] * 4 + target.ca.items[key] = target_comment + # transfer missing comments at specified indices + for index in indices: + if yaml_comment_entry_is_empty(target_comment[index]): + target_comment[index] = source_comment[index] -def transfer_missing_yaml_comments( - source: CommentedMap, target: CommentedMap, comment_normalisation: YamlCommentNormalisation, fully_missing_only: bool = False -) -> None: +def transfer_missing_yaml_comments(source: CommentedMap, target: CommentedMap, comment_normalisation: YamlCommentNormalisation) -> None: """ Transfers missing comments from source to target YAML. :param source: the source, from which to transfer missing comments :param target: the target map, whose comments will be updated. :param comment_normalisation: the comment normalisation to assume; if NONE, no comments are transferred - :param fully_missing_only: if True, only transfer comments for keys that have no comment definition at all (newly added) """ match comment_normalisation: case YamlCommentNormalisation.NONE: pass case YamlCommentNormalisation.LEADING | YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING: - transfer_missing_yaml_comments_by_index(source, target, [ITEM_COMMENT_INDEX_BEFORE], fully_missing_only=fully_missing_only) + transfer_missing_yaml_comments_by_index(source, target, [ITEM_COMMENT_INDEX_BEFORE]) case _: raise ValueError(f"Unhandled comment normalisation: {comment_normalisation}")