From 309b779a7ccb7976b1aedfb2fe9269385975c57b Mon Sep 17 00:00:00 2001 From: YaySushi Date: Sun, 24 Aug 2025 14:51:03 -0400 Subject: [PATCH 1/5] clean more type:ignore --- src/taskgraph/generator.py | 2 +- src/taskgraph/util/cached_tasks.py | 4 ++-- src/taskgraph/util/schema.py | 5 +++-- src/taskgraph/util/taskcluster.py | 7 ++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/taskgraph/generator.py b/src/taskgraph/generator.py index 36491bba7..c610f6c24 100644 --- a/src/taskgraph/generator.py +++ b/src/taskgraph/generator.py @@ -374,7 +374,7 @@ def _run(self): if parameters["enable_always_target"]: always_target_tasks = { t.label - for t in full_task_graph.tasks.values() # type: ignore + for t in full_task_graph.tasks.values() if t.attributes.get("always_target") if parameters["enable_always_target"] is True or t.kind in parameters["enable_always_target"] diff --git a/src/taskgraph/util/cached_tasks.py b/src/taskgraph/util/cached_tasks.py index 2f94bc3f9..e24afc179 100644 --- a/src/taskgraph/util/cached_tasks.py +++ b/src/taskgraph/util/cached_tasks.py @@ -37,8 +37,8 @@ def add_optimization( """ if (digest is None) == (digest_data is None): raise Exception("Must pass exactly one of `digest` and `digest_data`.") - if digest is None: - digest = hashlib.sha256("\n".join(digest_data).encode("utf-8")).hexdigest() # type: ignore + elif digest is None and digest_data is not None: + digest = hashlib.sha256("\n".join(digest_data).encode("utf-8")).hexdigest() if "cached-task-prefix" in config.graph_config["taskgraph"]: cache_prefix = config.graph_config["taskgraph"]["cached-task-prefix"] diff --git a/src/taskgraph/util/schema.py b/src/taskgraph/util/schema.py index ba72ff079..0079a1c4e 100644 --- a/src/taskgraph/util/schema.py +++ b/src/taskgraph/util/schema.py @@ -3,7 +3,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. -import collections import pprint import re @@ -12,6 +11,8 @@ import taskgraph from taskgraph.util.keyed_by import evaluate_keyed_by, iter_dot_path +from collections.abc import Mapping + def validate_schema(schema, obj, msg_prefix): """ @@ -184,7 +185,7 @@ def check_identifier(path, k): f"Unexpected type in YAML schema: {type(k).__name__} @ {path}" ) - if isinstance(sch, collections.abc.Mapping): # type: ignore + if isinstance(sch, Mapping): for k, v in sch.items(): child = f"{path}[{k!r}]" check_identifier(child, k) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index fe275662f..6755d9cc9 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -197,7 +197,7 @@ def find_task_id(index_path, use_proxy=False): try: response = _do_request(get_index_url(index_path, use_proxy)) except requests.exceptions.HTTPError as e: - if e.response.status_code == 404: # type: ignore + if e.response.status_code == 404: raise KeyError(f"index path {index_path} not found") raise return response.json()["taskId"] @@ -306,7 +306,7 @@ def cancel_task(task_id, use_proxy=False): def status_task(task_id, use_proxy=False): """Gets the status of a task given a task_id. - In testing mode, just logs that it would have retrieved status. + In testing mode, just logs that it would have retrieved status and return an empty dict Args: task_id (str): A task id. @@ -318,6 +318,7 @@ def status_task(task_id, use_proxy=False): """ if testing: logger.info(f"Would have gotten status for {task_id}.") + return {} else: resp = _do_request(get_task_url(task_id, use_proxy) + "/status") status = resp.json().get("status", {}) @@ -385,7 +386,7 @@ def state_task(task_id, use_proxy=False): if testing: logger.info(f"Would have gotten state for {task_id}.") else: - status = status_task(task_id, use_proxy=use_proxy).get("state") or "unknown" # type: ignore + status = status_task(task_id, use_proxy=use_proxy).get("state") or "unknown" return status From 38d76a7cbe01f58e0837d93ebadea89e8ebbfa6a Mon Sep 17 00:00:00 2001 From: YaySushi Date: Sun, 24 Aug 2025 15:08:41 -0400 Subject: [PATCH 2/5] nit --- src/taskgraph/util/taskcluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index 6755d9cc9..9d545360b 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -306,7 +306,7 @@ def cancel_task(task_id, use_proxy=False): def status_task(task_id, use_proxy=False): """Gets the status of a task given a task_id. - In testing mode, just logs that it would have retrieved status and return an empty dict + In testing mode, just logs that it would have retrieved status and return an empty dict. Args: task_id (str): A task id. From 40e723879df390b5319489a9e421d5af0131afc9 Mon Sep 17 00:00:00 2001 From: YaySushi Date: Sun, 24 Aug 2025 15:17:16 -0400 Subject: [PATCH 3/5] more --- src/taskgraph/generator.py | 2 +- src/taskgraph/taskgraph.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/taskgraph/generator.py b/src/taskgraph/generator.py index c610f6c24..901f03171 100644 --- a/src/taskgraph/generator.py +++ b/src/taskgraph/generator.py @@ -388,7 +388,7 @@ def _run(self): target_graph = full_task_graph.graph.transitive_closure(requested_tasks) target_task_graph = TaskGraph( {l: all_tasks[l] for l in target_graph.nodes}, - target_graph, # type: ignore + target_graph, ) yield self.verify( "target_task_graph", target_task_graph, graph_config, parameters diff --git a/src/taskgraph/taskgraph.py b/src/taskgraph/taskgraph.py index 11ba2f698..10466d849 100644 --- a/src/taskgraph/taskgraph.py +++ b/src/taskgraph/taskgraph.py @@ -41,7 +41,7 @@ def __contains__(self, label): def __iter__(self): "Iterate over tasks in undefined order" - return iter(self.tasks.values()) # type: ignore + return iter(self.tasks.values()) def to_json(self): "Return a JSON-able object representing the task graph, as documented" From c126d16c078d7ad18c3ad4329535dbad45e32462 Mon Sep 17 00:00:00 2001 From: YaySushi Date: Sun, 24 Aug 2025 15:38:37 -0400 Subject: [PATCH 4/5] reorder import --- src/taskgraph/util/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/taskgraph/util/schema.py b/src/taskgraph/util/schema.py index 0079a1c4e..4dd17b5d5 100644 --- a/src/taskgraph/util/schema.py +++ b/src/taskgraph/util/schema.py @@ -5,6 +5,7 @@ import pprint import re +from collections.abc import Mapping import voluptuous From 08ef627e26807d9ff6d4071d3caf64cc34d4e75e Mon Sep 17 00:00:00 2001 From: YaySushi Date: Mon, 25 Aug 2025 19:00:08 -0400 Subject: [PATCH 5/5] remove dup line --- src/taskgraph/util/schema.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/taskgraph/util/schema.py b/src/taskgraph/util/schema.py index 4dd17b5d5..3c5f4c955 100644 --- a/src/taskgraph/util/schema.py +++ b/src/taskgraph/util/schema.py @@ -12,8 +12,6 @@ import taskgraph from taskgraph.util.keyed_by import evaluate_keyed_by, iter_dot_path -from collections.abc import Mapping - def validate_schema(schema, obj, msg_prefix): """