Skip to content

Commit 24935ce

Browse files
committed
python: drop support for 3.8
1 parent d9108ac commit 24935ce

21 files changed

+199
-233
lines changed

boostedblob/_recover.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import datetime
1010
import urllib.parse
11-
from typing import Any, DefaultDict, Dict, List, Union
11+
from collections import defaultdict
12+
from typing import Any
1213

1314
from .boost import BoostExecutor
1415
from .path import AzurePath
@@ -25,8 +26,8 @@ def _xml_to_dict(element: etree.Element) -> Any:
2526

2627

2728
async def _listtree_versions_snapshots(
28-
prefix: Union[str, AzurePath]
29-
) -> Dict[AzurePath, List[Dict[str, Any]]]:
29+
prefix: str | AzurePath,
30+
) -> dict[AzurePath, list[dict[str, Any]]]:
3031
if isinstance(prefix, str):
3132
prefix = AzurePath.from_str(prefix)
3233

@@ -53,7 +54,7 @@ async def _listtree_versions_snapshots(
5354
)
5455
)
5556

56-
results = DefaultDict[AzurePath, List[Dict[str, Any]]](list)
57+
results = defaultdict[AzurePath, list[dict[str, Any]]](list)
5758
async for result in it:
5859
blobs = result.find("Blobs")
5960
assert blobs is not None
@@ -76,7 +77,7 @@ async def _undelete(path: AzurePath) -> AzurePath:
7677
return path
7778

7879

79-
async def _promote_candidate(path: AzurePath, candidate: Dict[str, Any]) -> None:
80+
async def _promote_candidate(path: AzurePath, candidate: dict[str, Any]) -> None:
8081
if "Snapshot" in candidate:
8182
source = "snapshot=" + urllib.parse.quote(candidate["Snapshot"])
8283
elif "VersionId" in candidate:
@@ -108,7 +109,7 @@ async def _delete_snapshot(path: AzurePath, snapshot: str) -> None:
108109

109110

110111
async def _recover_snapshot(
111-
path: AzurePath, candidate: Dict[str, Any], alternatives: List[Dict[str, Any]]
112+
path: AzurePath, candidate: dict[str, Any], alternatives: list[dict[str, Any]]
112113
) -> None:
113114
# https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-blob-overview#restoring-soft-deleted-objects
114115
await _undelete(path)
@@ -124,7 +125,7 @@ async def _recover_snapshot(
124125

125126

126127
async def _determine_candidate_and_recover(
127-
path: AzurePath, restore_ts: str, versions_snapshots: List[Dict[str, Any]], dry_run: bool = True
128+
path: AzurePath, restore_ts: str, versions_snapshots: list[dict[str, Any]], dry_run: bool = True
128129
) -> str:
129130
if any("VersionId" in b for b in versions_snapshots):
130131
# If using versioning, I think all blobs should have versions
@@ -178,7 +179,7 @@ async def _determine_candidate_and_recover(
178179
or snapshots[candidate_index].get("Deleted") == "true"
179180
)
180181

181-
def _to_ts_desc(b: Dict[str, Any]) -> str:
182+
def _to_ts_desc(b: dict[str, Any]) -> str:
182183
if "Snapshot" in b:
183184
return b["Snapshot"]
184185
assert candidate_index is not None
@@ -207,8 +208,8 @@ def _to_ts_desc(b: Dict[str, Any]) -> str:
207208

208209

209210
async def _recoverprefix(
210-
prefix: Union[str, AzurePath],
211-
restore_dt: Union[str, datetime.datetime],
211+
prefix: str | AzurePath,
212+
restore_dt: str | datetime.datetime,
212213
executor: BoostExecutor,
213214
dry_run: bool = True,
214215
) -> None:

boostedblob/azure_auth.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
import time
1111
import urllib.parse
12-
from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Sequence, Tuple
12+
from typing import TYPE_CHECKING, Any, Mapping, Sequence
1313

1414
from .xml import etree
1515

@@ -25,7 +25,7 @@
2525
SHARED_KEY = "shared_key"
2626

2727

28-
def load_credentials() -> Dict[str, Any]:
28+
def load_credentials() -> dict[str, Any]:
2929
# When AZURE_USE_IDENTITY=1, boostedblob will use the azure-identity package to retrieve AAD access tokens
3030
if os.getenv("AZURE_USE_IDENTITY", "0") == "1":
3131
return {"_azure_auth": "azure-identity"}
@@ -127,7 +127,7 @@ def load_credentials() -> Dict[str, Any]:
127127
)
128128

129129

130-
def load_stored_subscription_ids() -> List[str]:
130+
def load_stored_subscription_ids() -> list[str]:
131131
"""Return a list of subscription ids from the local azure profile.
132132
133133
The default subscription will appear first in the list.
@@ -146,7 +146,7 @@ def load_stored_subscription_ids() -> List[str]:
146146
return [sub["id"] for sub in subscriptions]
147147

148148

149-
async def get_access_token(cache_key: Tuple[str, Optional[str]]) -> Tuple[Any, float]:
149+
async def get_access_token(cache_key: tuple[str, str | None]) -> tuple[Any, float]:
150150
account, container = cache_key
151151
now = time.time()
152152
creds = load_credentials()
@@ -263,7 +263,7 @@ async def get_access_token(cache_key: Tuple[str, Optional[str]]) -> Tuple[Any, f
263263
)
264264

265265

266-
async def can_access_account(account: str, container: Optional[str], auth: Tuple[str, str]) -> bool:
266+
async def can_access_account(account: str, container: str | None, auth: tuple[str, str]) -> bool:
267267
from .request import Request, azure_auth_req
268268

269269
if not container:
@@ -343,8 +343,8 @@ def create_access_token_request(
343343

344344

345345
async def get_storage_account_id_with_subscription(
346-
subscription_id: str, account: str, auth: Tuple[str, str]
347-
) -> Optional[str]:
346+
subscription_id: str, account: str, auth: tuple[str, str]
347+
) -> str | None:
348348
from .request import Request, azure_auth_req
349349

350350
req = Request(
@@ -393,7 +393,7 @@ async def get_storage_account_id_with_subscription(
393393
return None
394394

395395

396-
async def get_storage_account_id(account: str, auth: Tuple[str, str]) -> Optional[str]:
396+
async def get_storage_account_id(account: str, auth: tuple[str, str]) -> str | None:
397397
from .request import Request, azure_auth_req
398398

399399
stored_subscription_ids = load_stored_subscription_ids()
@@ -432,8 +432,8 @@ async def get_storage_account_id(account: str, auth: Tuple[str, str]) -> Optiona
432432

433433

434434
async def get_storage_account_key(
435-
account: str, creds: Mapping[str, Any], container_hint: Optional[str] = None
436-
) -> Optional[Tuple[Any, float]]:
435+
account: str, creds: Mapping[str, Any], container_hint: str | None = None
436+
) -> tuple[Any, float] | None:
437437
from .request import Request, azure_auth_req
438438

439439
# get an access token for the management service
@@ -524,7 +524,7 @@ def canonicalized_headers() -> str:
524524
return f"SharedKey {storage_account}:{signature}"
525525

526526

527-
async def get_sas_token(cache_key: Tuple[str, Optional[str]]) -> Tuple[Any, float]:
527+
async def get_sas_token(cache_key: tuple[str, str | None]) -> tuple[Any, float]:
528528
from .globals import config
529529
from .request import Request, azure_auth_req
530530

@@ -573,7 +573,7 @@ async def get_sas_token(cache_key: Tuple[str, Optional[str]]) -> Tuple[Any, floa
573573
return user_delegation_key, time.time() + AZURE_SAS_TOKEN_EXPIRATION_SECONDS
574574

575575

576-
async def generate_signed_url(path: AzurePath) -> Tuple[str, datetime.datetime]:
576+
async def generate_signed_url(path: AzurePath) -> tuple[str, datetime.datetime]:
577577
# https://docs.microsoft.com/en-us/rest/api/storageservices/delegate-access-with-shared-access-signature
578578
# https://docs.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas
579579
# https://docs.microsoft.com/en-us/rest/api/storageservices/service-sas-examples

0 commit comments

Comments
 (0)