Skip to content

Commit 3807beb

Browse files
committed
Update typing for Python 3.9
1 parent eea4dc6 commit 3807beb

File tree

11 files changed

+31
-36
lines changed

11 files changed

+31
-36
lines changed

circfirm/backend/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import enum
1111
import re
12-
from typing import Tuple
1312

1413

1514
class Language(enum.Enum):
@@ -60,7 +59,7 @@ def get_uf2_filename(board_id: str, version: str, language: str = "en_US") -> st
6059
return f"adafruit-circuitpython-{board_id}-{language}-{version}.uf2"
6160

6261

63-
def parse_firmware_info(uf2_filename: str) -> Tuple[str, str]:
62+
def parse_firmware_info(uf2_filename: str) -> tuple[str, str]:
6463
"""Get firmware info."""
6564
regex_match = re.match(FIRMWARE_REGEX, uf2_filename)
6665
if regex_match is None:

circfirm/backend/cache.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
import os
1111
import pathlib
12-
import re
13-
from typing import Dict, List, Optional, Set, Tuple
12+
from typing import Optional
1413

1514
import packaging.version
1615
import requests
@@ -57,12 +56,12 @@ def download_uf2(board_id: str, version: str, language: str = "en_US") -> None:
5756
uf2file.write(response.content)
5857

5958

60-
def get_sorted_boards(board_id: Optional[str]) -> Dict[str, Dict[str, Set[str]]]:
59+
def get_sorted_boards(board_id: Optional[str]) -> dict[str, dict[str, set[str]]]:
6160
"""Get a sorted collection of boards, versions, and languages."""
62-
boards: Dict[str, Dict[str, Set[str]]] = {}
61+
boards: dict[str, dict[str, set[str]]] = {}
6362
for board_folder in sorted(os.listdir(circfirm.UF2_ARCHIVE)):
64-
versions: Dict[str, List[str]] = {}
65-
sorted_versions: Dict[str, Set[str]] = {}
63+
versions: dict[str, list[str]] = {}
64+
sorted_versions: dict[str, set[str]] = {}
6665
if board_id is not None and board_id != board_folder:
6766
continue
6867
board_folder_full = get_board_folder(board_folder)

circfirm/backend/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pathlib
1111
import re
12-
from typing import Optional, Tuple
12+
from typing import Optional
1313

1414
import psutil
1515

@@ -21,7 +21,7 @@
2121
)
2222

2323

24-
def get_board_info(device_path: str) -> Tuple[str, str]:
24+
def get_board_info(device_path: str) -> tuple[str, str]:
2525
"""Get the attached CircuitPytho board's name and version."""
2626
bootout_file = pathlib.Path(device_path) / circfirm.BOOTOUT_FILE
2727
with open(bootout_file, encoding="utf-8") as infofile:

circfirm/backend/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import datetime
1111
import re
12-
from typing import List, Tuple, TypedDict
12+
from typing import TypedDict
1313

1414
import requests
1515

@@ -42,7 +42,7 @@ class GitTreeItem(TypedDict):
4242
url: str
4343

4444

45-
def get_rate_limit() -> Tuple[int, int, datetime.datetime]:
45+
def get_rate_limit() -> tuple[int, int, datetime.datetime]:
4646
"""Get the rate limit for the GitHub REST endpoint."""
4747
response = requests.get(
4848
url="https://api.github.com/rate_limit",
@@ -55,7 +55,7 @@ def get_rate_limit() -> Tuple[int, int, datetime.datetime]:
5555
return available, total, reset_time
5656

5757

58-
def get_board_id_list(token: str) -> List[str]:
58+
def get_board_id_list(token: str) -> list[str]:
5959
"""Get a list of CircuitPython boards."""
6060
boards = set()
6161
headers = BASE_REQUESTS_HEADERS.copy()
@@ -69,7 +69,7 @@ def get_board_id_list(token: str) -> List[str]:
6969
headers=headers,
7070
)
7171
try:
72-
tree_items: List[GitTreeItem] = response.json()["tree"]
72+
tree_items: list[GitTreeItem] = response.json()["tree"]
7373
except KeyError as err:
7474
raise ValueError("Could not parse JSON response, check token") from err
7575
for tree_item in tree_items:

circfirm/backend/s3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
import re
11-
from typing import List, Optional
11+
from typing import Optional
1212

1313
import boto3
1414
import botocore
@@ -27,7 +27,7 @@
2727

2828
def get_board_versions(
2929
board_id: str, language: str = "en_US", *, regex: Optional[str] = None
30-
) -> List[str]:
30+
) -> list[str]:
3131
"""Get a list of CircuitPython versions for a given board."""
3232
prefix = f"bin/{board_id}/{language}"
3333
firmware_regex = circfirm.backend.FIRMWARE_REGEX_PATTERN.replace(

circfirm/cli/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import shutil
1414
import sys
1515
import time
16-
from typing import Any, Callable, Dict, Iterable, Optional, Tuple, TypeVar
16+
from collections.abc import Iterable
17+
from typing import Any, Callable, Optional, TypeVar
1718

1819
import click
1920
import click_spinner
@@ -47,7 +48,7 @@ def get_board_id(
4748
bootloader: Optional[str],
4849
board: Optional[str],
4950
timeout: int = -1,
50-
) -> Tuple[str, str]:
51+
) -> tuple[str, str]:
5152
"""Get the board ID of a device via CLI."""
5253
if not board:
5354
if not circuitpy and bootloader:
@@ -74,7 +75,7 @@ def get_board_id(
7475
return bootloader, board
7576

7677

77-
def get_connection_status() -> Tuple[Optional[str], Optional[str]]:
78+
def get_connection_status() -> tuple[Optional[str], Optional[str]]:
7879
"""Get the status of a connectted CircuitPython device as a CIRCUITPY and bootloader location."""
7980
circuitpy = circfirm.backend.device.find_circuitpy()
8081
bootloader = circfirm.backend.device.find_bootloader()
@@ -129,7 +130,7 @@ def announce_and_await(
129130
msg: str,
130131
func: Callable[..., _T],
131132
args: Iterable = (),
132-
kwargs: Optional[Dict[str, Any]] = None,
133+
kwargs: Optional[dict[str, Any]] = None,
133134
*,
134135
use_spinner: bool = True,
135136
) -> _T:
@@ -154,7 +155,7 @@ def announce_and_await(
154155
raise err
155156

156157

157-
def get_settings() -> Dict[str, Any]:
158+
def get_settings() -> dict[str, Any]:
158159
"""Get the contents of the settings file."""
159160
with open(circfirm.SETTINGS_FILE, encoding="utf-8") as yamlfile:
160161
return yaml.safe_load(yamlfile)

circfirm/cli/current.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
Author(s): Alec Delaney
88
"""
99

10-
from typing import Tuple
11-
1210
import click
1311

1412
import circfirm.backend.device
1513
import circfirm.cli
1614

1715

18-
def get_board_info() -> Tuple[str, str]:
16+
def get_board_info() -> tuple[str, str]:
1917
"""Get board info via the CLI."""
2018
circuitpy, _ = circfirm.cli.get_connection_status()
2119
if not circuitpy:

circfirm/startup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
import os
1111
import pathlib
1212
import shutil
13-
from typing import List, Tuple
1413

1514
import click
1615

17-
FOLDER_LIST: List[str] = []
18-
FILE_LIST: List[str] = []
19-
TEMPLATE_LIST: List[Tuple[str, str]] = []
16+
FOLDER_LIST: list[str] = []
17+
FILE_LIST: list[str] = []
18+
TEMPLATE_LIST: list[tuple[str, str]] = []
2019

2120

2221
def specify_app_dir(app_name: str) -> str:

scripts/rmdir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
for name in children:
2121
filepath = os.path.join(root, name)
2222
os.chmod(filepath, 0o777)
23-
23+
2424
shutil.rmtree(target)

tests/backend/test_backend_s3.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from collections import namedtuple
1111
from functools import partial
12-
from typing import List
1312

1413
import boto3.resources.collection
1514
import pytest
@@ -20,8 +19,8 @@
2019

2120

2221
def get_fake_s3_objects(
23-
board: str, keys: List[str], *args, **kwargs
24-
) -> List[MockS3Object]:
22+
board: str, keys: list[str], *args, **kwargs
23+
) -> list[MockS3Object]:
2524
"""Create a set of fake S3 objects."""
2625
template_link = (
2726
f"bin/{board}/en_US/adafruit-circuitpython-{board}-en_US-[version].uf2"

0 commit comments

Comments
 (0)