Skip to content

Commit f2aeb97

Browse files
authored
Merge pull request #2731 from NicholasTanz/updateAnnotations
update python annotations
2 parents 74c0ad3 + eb6d82f commit f2aeb97

28 files changed

+187
-186
lines changed

examples/manual_repo/basic_repo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import tempfile
2626
from datetime import datetime, timedelta, timezone
2727
from pathlib import Path
28-
from typing import Dict
2928

3029
from securesystemslib.signer import CryptoSigner, Signer
3130

@@ -87,8 +86,8 @@ def _in(days: float) -> datetime:
8786

8887
# Define containers for role objects and cryptographic keys created below. This
8988
# allows us to sign and write metadata in a batch more easily.
90-
roles: Dict[str, Metadata] = {}
91-
signers: Dict[str, Signer] = {}
89+
roles: dict[str, Metadata] = {}
90+
signers: dict[str, Signer] = {}
9291

9392

9493
# Targets (integrity)

examples/manual_repo/hashed_bin_delegation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import hashlib
2020
import os
2121
import tempfile
22+
from collections.abc import Iterator
2223
from datetime import datetime, timedelta, timezone
2324
from pathlib import Path
24-
from typing import Dict, Iterator, List, Tuple
2525

2626
from securesystemslib.signer import CryptoSigner, Signer
2727

@@ -42,8 +42,8 @@ def _in(days: float) -> datetime:
4242
)
4343

4444

45-
roles: Dict[str, Metadata[Targets]] = {}
46-
signers: Dict[str, Signer] = {}
45+
roles: dict[str, Metadata[Targets]] = {}
46+
signers: dict[str, Signer] = {}
4747

4848
# Hash bin delegation
4949
# ===================
@@ -96,7 +96,7 @@ def _bin_name(low: int, high: int) -> str:
9696
return f"{low:0{PREFIX_LEN}x}-{high:0{PREFIX_LEN}x}"
9797

9898

99-
def generate_hash_bins() -> Iterator[Tuple[str, List[str]]]:
99+
def generate_hash_bins() -> Iterator[tuple[str, list[str]]]:
100100
"""Returns generator for bin names and hash prefixes per bin."""
101101
# Iterate over the total number of hash prefixes in 'bin size'-steps to
102102
# generate bin names and a list of hash prefixes served by each bin.

examples/manual_repo/succinct_hash_bin_delegations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import tempfile
2424
from datetime import datetime, timedelta, timezone
2525
from pathlib import Path
26-
from typing import Dict
2726

2827
from securesystemslib.signer import CryptoSigner
2928

@@ -105,7 +104,7 @@
105104
bit_length=BIT_LENGTH,
106105
name_prefix=NAME_PREFIX,
107106
)
108-
delegations_keys_info: Dict[str, Key] = {}
107+
delegations_keys_info: dict[str, Key] = {}
109108
delegations_keys_info[bins_key.keyid] = bins_key
110109

111110
targets.signed.delegations = Delegations(
@@ -119,7 +118,7 @@
119118

120119
assert targets.signed.delegations.succinct_roles is not None # make mypy happy
121120

122-
delegated_bins: Dict[str, Metadata[Targets]] = {}
121+
delegated_bins: dict[str, Metadata[Targets]] = {}
123122
for delegated_bin_name in targets.signed.delegations.succinct_roles.get_roles():
124123
delegated_bins[delegated_bin_name] = Metadata(
125124
Targets(expires=expiration_date)

examples/repository/_simplerepo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
from collections import defaultdict
1010
from datetime import datetime, timedelta, timezone
11-
from typing import Dict, List, Union
11+
from typing import Union
1212

1313
from securesystemslib.signer import CryptoSigner, Key, Signer
1414

@@ -59,16 +59,16 @@ class SimpleRepository(Repository):
5959

6060
def __init__(self) -> None:
6161
# all versions of all metadata
62-
self.role_cache: Dict[str, List[Metadata]] = defaultdict(list)
62+
self.role_cache: dict[str, list[Metadata]] = defaultdict(list)
6363
# all current keys
64-
self.signer_cache: Dict[str, List[Signer]] = defaultdict(list)
64+
self.signer_cache: dict[str, list[Signer]] = defaultdict(list)
6565
# all target content
66-
self.target_cache: Dict[str, bytes] = {}
66+
self.target_cache: dict[str, bytes] = {}
6767
# version cache for snapshot and all targets, updated in close().
6868
# The 'defaultdict(lambda: ...)' trick allows close() to easily modify
6969
# the version without always creating a new MetaFile
7070
self._snapshot_info = MetaFile(1)
71-
self._targets_infos: Dict[str, MetaFile] = defaultdict(
71+
self._targets_infos: dict[str, MetaFile] = defaultdict(
7272
lambda: MetaFile(1)
7373
)
7474

@@ -84,7 +84,7 @@ def __init__(self) -> None:
8484
pass
8585

8686
@property
87-
def targets_infos(self) -> Dict[str, MetaFile]:
87+
def targets_infos(self) -> dict[str, MetaFile]:
8888
return self._targets_infos
8989

9090
@property

examples/uploader/_localrepo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import logging
1010
import os
1111
from datetime import datetime, timedelta, timezone
12-
from typing import Dict
1312

1413
import requests
1514
from securesystemslib.signer import CryptoSigner, Signer
@@ -50,7 +49,7 @@ def __init__(self, metadata_dir: str, key_dir: str, base_url: str):
5049
self.updater.refresh()
5150

5251
@property
53-
def targets_infos(self) -> Dict[str, MetaFile]:
52+
def targets_infos(self) -> dict[str, MetaFile]:
5453
raise NotImplementedError # we never call snapshot
5554

5655
@property

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "tuf"
1010
description = "A secure updater framework for Python"
1111
readme = "README.md"
1212
license = { text = "MIT OR Apache-2.0" }
13-
requires-python = ">=3.8"
13+
requires-python = ">=3.9"
1414
authors = [
1515
{ email = "theupdateframework@googlegroups.com" },
1616
]

tests/generated_data/generate_md.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
import sys
88
from datetime import datetime, timezone
9-
from typing import List, Optional
9+
from typing import Optional
1010

1111
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
1212
from securesystemslib.signer import CryptoSigner, Signer, SSlibKey
@@ -16,13 +16,13 @@
1616
from tuf.api.serialization.json import JSONSerializer
1717

1818
# Hardcode keys and expiry time to achieve reproducibility.
19-
public_values: List[str] = [
19+
public_values: list[str] = [
2020
"b11d2ff132c033a657318c74c39526476c56de7556c776f11070842dbc4ac14c",
2121
"250f9ae3d1d3d5c419a73cfb4a470c01de1d5d3d61a3825416b5f5d6b88f4a30",
2222
"82380623abb9666d4bf274b1a02577469445a972e5650d270101faa5107b19c8",
2323
"0e6738fc1ac6fb4de680b4be99ecbcd99b030f3963f291277eef67bb9bd123e9",
2424
]
25-
private_values: List[bytes] = [
25+
private_values: list[bytes] = [
2626
bytes.fromhex(
2727
"510e5e04d7a364af850533856eacdf65d30cc0f8803ecd5fdc0acc56ca2aa91c"
2828
),
@@ -36,14 +36,14 @@
3636
"7e2e751145d1b22f6e40d4ba2aa47158207acfd3c003f1cbd5a08141dfc22a15"
3737
),
3838
]
39-
keyids: List[str] = [
39+
keyids: list[str] = [
4040
"5822582e7072996c1eef1cec24b61115d364987faa486659fe3d3dce8dae2aba",
4141
"09d440e3725cec247dcb8703b646a87dd2a4d75343e8095c036c32795eefe3b9",
4242
"3458204ed467519c19a5316eb278b5608472a1bbf15850ebfb462d5315e4f86d",
4343
"2be5c21e3614f9f178fb49c4a34d0c18ffac30abd14ced917c60a52c8d8094b7",
4444
]
4545

46-
signers: List[Signer] = []
46+
signers: list[Signer] = []
4747
for index in range(len(keyids)):
4848
key = SSlibKey(
4949
keyids[index],

tests/repository_simulator.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
import logging
4747
import os
4848
import tempfile
49+
from collections.abc import Iterator
4950
from dataclasses import dataclass, field
50-
from typing import Dict, Iterator, List, Optional, Tuple
51+
from typing import Optional
5152
from urllib import parse
5253

5354
import securesystemslib.hash as sslib_hash
@@ -80,8 +81,8 @@
8081
class FetchTracker:
8182
"""Fetcher counter for metadata and targets."""
8283

83-
metadata: List[Tuple[str, Optional[int]]] = field(default_factory=list)
84-
targets: List[Tuple[str, Optional[str]]] = field(default_factory=list)
84+
metadata: list[tuple[str, Optional[int]]] = field(default_factory=list)
85+
targets: list[tuple[str, Optional[str]]] = field(default_factory=list)
8586

8687

8788
@dataclass
@@ -96,18 +97,18 @@ class RepositorySimulator(FetcherInterface):
9697
"""Simulates a repository that can be used for testing."""
9798

9899
def __init__(self) -> None:
99-
self.md_delegates: Dict[str, Metadata[Targets]] = {}
100+
self.md_delegates: dict[str, Metadata[Targets]] = {}
100101

101102
# other metadata is signed on-demand (when fetched) but roots must be
102103
# explicitly published with publish_root() which maintains this list
103-
self.signed_roots: List[bytes] = []
104+
self.signed_roots: list[bytes] = []
104105

105106
# signers are used on-demand at fetch time to sign metadata
106107
# keys are roles, values are dicts of {keyid: signer}
107-
self.signers: Dict[str, Dict[str, Signer]] = {}
108+
self.signers: dict[str, dict[str, Signer]] = {}
108109

109110
# target downloads are served from this dict
110-
self.target_files: Dict[str, RepositoryTarget] = {}
111+
self.target_files: dict[str, RepositoryTarget] = {}
111112

112113
# Whether to compute hashes and length for meta in snapshot/timestamp
113114
self.compute_metafile_hashes_length = False
@@ -143,7 +144,7 @@ def snapshot(self) -> Snapshot:
143144
def targets(self) -> Targets:
144145
return self.md_targets.signed
145146

146-
def all_targets(self) -> Iterator[Tuple[str, Targets]]:
147+
def all_targets(self) -> Iterator[tuple[str, Targets]]:
147148
"""Yield role name and signed portion of targets one by one."""
148149
yield Targets.type, self.md_targets.signed
149150
for role, md in self.md_delegates.items():
@@ -287,7 +288,7 @@ def fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
287288

288289
def _compute_hashes_and_length(
289290
self, role: str
290-
) -> Tuple[Dict[str, str], int]:
291+
) -> tuple[dict[str, str], int]:
291292
data = self.fetch_metadata(role)
292293
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
293294
digest_object.update(data)

tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from copy import copy, deepcopy
1313
from datetime import datetime, timedelta, timezone
1414
from pathlib import Path
15-
from typing import ClassVar, Dict, Optional
15+
from typing import ClassVar, Optional
1616

1717
from securesystemslib import exceptions as sslib_exceptions
1818
from securesystemslib import hash as sslib_hash
@@ -54,7 +54,7 @@ class TestMetadata(unittest.TestCase):
5454
temporary_directory: ClassVar[str]
5555
repo_dir: ClassVar[str]
5656
keystore_dir: ClassVar[str]
57-
signers: ClassVar[Dict[str, Signer]]
57+
signers: ClassVar[dict[str, Signer]]
5858

5959
@classmethod
6060
def setUpClass(cls) -> None:
@@ -763,7 +763,7 @@ def test_targets_key_api(self) -> None:
763763
}
764764
)
765765
assert isinstance(targets.delegations, Delegations)
766-
assert isinstance(targets.delegations.roles, Dict)
766+
assert isinstance(targets.delegations.roles, dict)
767767
targets.delegations.roles["role2"] = delegated_role
768768

769769
key_dict = {

tests/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tempfile
1010
import unittest
1111
from pathlib import Path
12-
from typing import ClassVar, List
12+
from typing import ClassVar
1313

1414
from tests import utils
1515

@@ -44,7 +44,7 @@ def tearDown(self) -> None:
4444
shutil.rmtree(self.base_test_dir)
4545

4646
def _run_script_and_assert_files(
47-
self, script_name: str, filenames_created: List[str]
47+
self, script_name: str, filenames_created: list[str]
4848
) -> None:
4949
"""Run script in exmple dir and assert that it created the
5050
files corresponding to the passed filenames inside a 'tmp*' test dir at

0 commit comments

Comments
 (0)