6060
6161import logging
6262import os
63- from typing import Any , Dict , List , Optional
63+ from typing import Any , Dict , List , Optional , Set , Tuple
6464from urllib import parse
6565
6666from securesystemslib import util as sslib_util
6767
6868from tuf import exceptions
69+ from tuf .api .metadata import Targets
6970from tuf .ngclient ._internal import requests_fetcher , trusted_metadata_set
7071from tuf .ngclient .config import UpdaterConfig
7172from tuf .ngclient .fetcher import FetcherInterface
@@ -141,7 +142,9 @@ def refresh(self) -> None:
141142 self ._load_snapshot ()
142143 self ._load_targets ("targets" , "root" )
143144
144- def get_one_valid_targetinfo (self , target_path : str ) -> Dict :
145+ def get_one_valid_targetinfo (
146+ self , target_path : str
147+ ) -> Optional [Dict [str , Any ]]:
145148 """Returns target information for 'target_path'.
146149
147150 The return value can be used as an argument to
@@ -366,15 +369,17 @@ def _load_targets(self, role: str, parent_role: str) -> None:
366369 self ._trusted_set .update_delegated_targets (data , role , parent_role )
367370 self ._persist_metadata (role , data )
368371
369- def _preorder_depth_first_walk (self , target_filepath : str ) -> Dict :
372+ def _preorder_depth_first_walk (
373+ self , target_filepath : str
374+ ) -> Optional [Dict [str , Any ]]:
370375 """
371376 Interrogates the tree of target delegations in order of appearance
372377 (which implicitly order trustworthiness), and returns the matching
373378 target found in the most trusted role.
374379 """
375380
376381 role_names = [("targets" , "root" )]
377- visited_role_names = set ()
382+ visited_role_names : Set [ Tuple [ str , str ]] = set ()
378383 number_of_delegations = self .config .max_delegations
379384
380385 # Preorder depth-first traversal of the graph of target delegations.
@@ -392,7 +397,7 @@ def _preorder_depth_first_walk(self, target_filepath: str) -> Dict:
392397 # its targets, delegations, and child roles can be inspected.
393398 self ._load_targets (role_name , parent_role )
394399
395- role_metadata = self ._trusted_set [role_name ].signed
400+ role_metadata : Targets = self ._trusted_set [role_name ].signed
396401 target = role_metadata .targets .get (target_filepath )
397402
398403 if target is not None :
0 commit comments