From ea4933ea4c71cd1bae031f59b4b32eec52c342ff Mon Sep 17 00:00:00 2001 From: Alexander Neben Date: Mon, 16 Mar 2026 07:02:53 -0700 Subject: [PATCH] SERVER-121688: Add type hints to resmoke dictionary and jscomment utils (#49628) Co-authored-by: Claude Code GitOrigin-RevId: eeb78d5a0ae9dac711ea22339b55913a4e165f95 --- buildscripts/resmokelib/utils/dictionary.py | 14 ++++++++------ buildscripts/resmokelib/utils/jscomment.py | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/buildscripts/resmokelib/utils/dictionary.py b/buildscripts/resmokelib/utils/dictionary.py index 1edadf8fa31..fd419537b41 100644 --- a/buildscripts/resmokelib/utils/dictionary.py +++ b/buildscripts/resmokelib/utils/dictionary.py @@ -1,9 +1,9 @@ """Utility functions for working with Dict-type structures.""" -from typing import MutableMapping +from typing import Any, MutableMapping -def merge_dicts(dict1, dict2): +def merge_dicts(dict1: dict[str, Any], dict2: dict[str, Any]) -> dict[str, Any]: """Recursively merges dict2 into dict1.""" if not (isinstance(dict1, MutableMapping) and isinstance(dict2, MutableMapping)): return dict2 @@ -19,7 +19,9 @@ def merge_dicts(dict1, dict2): return dict1 -def extend_dict_lists(dict1, dict2): +def extend_dict_lists( + dict1: MutableMapping[str, Any] | list[Any], dict2: MutableMapping[str, Any] | list[Any] +) -> MutableMapping[str, Any] | list[Any]: """Recursively merges dict2 into dict1, by extending the lists on dict1. All terminal elements in dict2 must be lists. For each terminal element in dict2, the matching @@ -50,7 +52,7 @@ def extend_dict_lists(dict1, dict2): - element 4 """ - def assert_valid_instance(obj): + def assert_valid_instance(obj: Any) -> None: if not isinstance(obj, (list, MutableMapping)): raise ValueError(f"the {obj} field must be a list") @@ -76,7 +78,7 @@ def extend_dict_lists(dict1, dict2): return dict1 -def get_dict_value(dict1, path): +def get_dict_value(dict1: MutableMapping[str, Any], path: list[str]) -> Any: current_object = dict1 for key in path: @@ -88,7 +90,7 @@ def get_dict_value(dict1, path): return current_object -def set_dict_value(dict1, path, value): +def set_dict_value(dict1: MutableMapping[str, Any], path: list[str], value: Any) -> None: current_object = dict1 for key in path[:-1]: diff --git a/buildscripts/resmokelib/utils/jscomment.py b/buildscripts/resmokelib/utils/jscomment.py index 04719a2729f..4c60d1e2628 100644 --- a/buildscripts/resmokelib/utils/jscomment.py +++ b/buildscripts/resmokelib/utils/jscomment.py @@ -11,7 +11,7 @@ _JSTEST_TAGS_RE = re.compile(r".*@tags\s*:\s*(\[[^\]]*\])", re.DOTALL) @functools.cache -def get_tags(pathname): +def get_tags(pathname: str) -> list[str]: """Return the list of tags found in the (JS-style) comments of 'pathname'. The definition can span multiple lines, use unquoted, @@ -68,7 +68,7 @@ def get_tags(pathname): return [] -def _strip_jscomments(string): +def _strip_jscomments(string: str | bytes) -> str: """Strip JS comments from a 'string'. Given a string 'string' that represents the contents after the "@tags:"