Skip to content

Commit 6a7513a

Browse files
committed
pyproject: update black to target Python 3.10
This comes with a bit of reformatting since with statements can now use parentheses since Python 3.9.
1 parent a58f94d commit 6a7513a

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

pybricksdev/cli/flash.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,19 @@ async def tick(callback):
391391
callback(CHUNK)
392392

393393
print("Erasing memory and preparing firmware download...")
394-
with logging_redirect_tqdm(), tqdm(
395-
total=len(firmware), unit="B", unit_scale=True
396-
) as pbar:
394+
with (
395+
logging_redirect_tqdm(),
396+
tqdm(total=len(firmware), unit="B", unit_scale=True) as pbar,
397+
):
397398
await asyncio.gather(
398399
bootloader.erase_and_begin_download(len(firmware)), tick(pbar.update)
399400
)
400401

401402
print("Downloading firmware...")
402-
with logging_redirect_tqdm(), tqdm(
403-
total=len(firmware), unit="B", unit_scale=True
404-
) as pbar:
403+
with (
404+
logging_redirect_tqdm(),
405+
tqdm(total=len(firmware), unit="B", unit_scale=True) as pbar,
406+
):
405407
await bootloader.download(firmware, pbar.update)
406408

407409
print("Verifying...", end="", flush=True)

pybricksdev/cli/oad.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ def on_disconnect(_):
7373
disconnect_event.set()
7474

7575
# long timeout in case pairing is needed
76-
async with asyncio.timeout(60), BleakClient(
77-
device, on_disconnect
78-
) as client, OADImageIdentify(client) as image_identify, OADControlPoint(
79-
client
80-
) as control_point:
76+
async with (
77+
asyncio.timeout(60),
78+
BleakClient(device, on_disconnect) as client,
79+
OADImageIdentify(client) as image_identify,
80+
OADControlPoint(client) as control_point,
81+
):
8182
image_block = OADImageBlock(client)
8283

8384
print(f"Connected to {device.name}")
@@ -107,9 +108,10 @@ def on_disconnect(_):
107108

108109
print("Flashing...")
109110

110-
with logging_redirect_tqdm(), tqdm(
111-
total=header.image_length, unit="B", unit_scale=True
112-
) as pbar:
111+
with (
112+
logging_redirect_tqdm(),
113+
tqdm(total=header.image_length, unit="B", unit_scale=True) as pbar,
114+
):
113115
async with asyncio.TaskGroup() as group:
114116
try:
115117
async for (
@@ -161,9 +163,11 @@ async def dump_oad_info():
161163
return
162164

163165
# long timeout in case pairing is needed
164-
async with asyncio.timeout(30), BleakClient(device) as client, OADControlPoint(
165-
client
166-
) as control_point:
166+
async with (
167+
asyncio.timeout(30),
168+
BleakClient(device) as client,
169+
OADControlPoint(client) as control_point,
170+
):
167171
sw_ver = await control_point.get_software_version()
168172
print(
169173
f"Software version: app={sw_ver.app.major}.{sw_ver.app.minor}, stack={sw_ver.stack.major}.{sw_ver.stack.minor}"

pybricksdev/connections/pybricks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ async def download_user_program(self, program: bytes) -> None:
473473
payload_size = self._max_write_size - 5
474474

475475
# write program data with progress bar
476-
with logging_redirect_tqdm(), tqdm(
477-
total=len(program), unit="B", unit_scale=True
478-
) as pbar:
476+
with (
477+
logging_redirect_tqdm(),
478+
tqdm(total=len(program), unit="B", unit_scale=True) as pbar,
479+
):
479480
for i, c in enumerate(chunk(program, payload_size)):
480481
await self.write_gatt_char(
481482
PYBRICKS_COMMAND_EVENT_UUID,
@@ -678,9 +679,10 @@ async def send_block(data: bytes) -> None:
678679
await send_block(length)
679680

680681
# Send the data chunk by chunk
681-
with logging_redirect_tqdm(), tqdm(
682-
total=len(mpy), unit="B", unit_scale=True
683-
) as pbar:
682+
with (
683+
logging_redirect_tqdm(),
684+
tqdm(total=len(mpy), unit="B", unit_scale=True) as pbar,
685+
):
684686
for c in chunk(mpy, 100):
685687
await send_block(c)
686688
pbar.update(len(c))

pybricksdev/flash.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ async def flash(self, firmware, metadata):
220220
logger.debug("Begin update.")
221221

222222
# Maintain progress using tqdm
223-
with logging_redirect_tqdm(), tqdm(
224-
total=firmware_size, unit="B", unit_scale=True
225-
) as pbar:
223+
with (
224+
logging_redirect_tqdm(),
225+
tqdm(total=firmware_size, unit="B", unit_scale=True) as pbar,
226+
):
226227

227228
def reader():
228229
while True:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ requires = ["poetry-core>=1.0.0"]
7171
build-backend = "poetry.core.masonry.api"
7272

7373
[tool.black]
74-
target-version = ['py38']
74+
target-version = ['py310']
7575

7676
[tool.isort]
7777
profile = "black"

0 commit comments

Comments
 (0)