Skip to content

Commit 87ce5bc

Browse files
committed
fix some linting issues
1 parent 3a595e4 commit 87ce5bc

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

pybricksdev/cli/__init__.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,35 @@ def is_pybricks_usb(dev):
233233
await hub.download(script_path)
234234

235235
if args.stay_connected:
236-
response_options = ["Recompile and Run", "Recompile and Download", "Exit"]
236+
response_options = [
237+
"Recompile and Run",
238+
"Recompile and Download",
239+
"Exit",
240+
]
237241
while True:
238242
try:
239-
response = await hub.race_user_program_start(questionary.select("Would you like to re-compile your code?", response_options).ask_async())
243+
response = await hub.race_user_program_start(
244+
questionary.select(
245+
"Would you like to re-compile your code?",
246+
response_options,
247+
).ask_async()
248+
)
240249
except RuntimeError as e:
241250

242251
async def reconnect_hub():
243252
if await questionary.confirm(
244-
"\nThe hub has been disconnected. Would you like to re-connect?").ask_async():
253+
"\nThe hub has been disconnected. Would you like to re-connect?"
254+
).ask_async():
245255
if args.conntype == "ble":
246-
print(f"Searching for {args.name or 'any hub with Pybricks service'}...")
256+
print(
257+
f"Searching for {args.name or 'any hub with Pybricks service'}..."
258+
)
247259
device_or_address = await find_ble(args.name)
248260
hub = PybricksHubBLE(device_or_address)
249261
elif args.conntype == "usb":
250-
device_or_address = find_usb(custom_match=is_pybricks_usb)
262+
device_or_address = find_usb(
263+
custom_match=is_pybricks_usb
264+
)
251265
hub = PybricksHubUSB(device_or_address)
252266

253267
await hub.connect()
@@ -259,20 +273,26 @@ async def reconnect_hub():
259273
else:
260274
exit()
261275

262-
if hub.status_observable.value & StatusFlag.POWER_BUTTON_PRESSED:
276+
if (hub.status_observable.value
277+
& StatusFlag.POWER_BUTTON_PRESSED
278+
):
263279
try:
264280
await hub._wait_for_user_program_stop(2.1)
265281
continue
266282

267283
except RuntimeError as e:
268-
if hub.connection_state_observable.value == ConnectionState.DISCONNECTED:
284+
if (hub.connection_state_observable.value
285+
== ConnectionState.DISCONNECTED
286+
):
269287
hub = await reconnect_hub()
270288
continue
271289

272290
else:
273291
raise e
274292

275-
elif hub.connection_state_observable.value == ConnectionState.DISCONNECTED:
293+
elif (hub.connection_state_observable.value
294+
== ConnectionState.DISCONNECTED
295+
):
276296
# let terminal cool off before making a new prompt
277297
await asyncio.sleep(0.3)
278298

@@ -283,20 +303,19 @@ async def reconnect_hub():
283303
raise e
284304

285305
with _get_script_path(args.file) as script_path:
286-
if response == response_options[0]:
287-
await hub.run(script_path, True)
288-
elif response == response_options[1]:
289-
await hub.download(script_path)
290-
else:
291-
exit(1)
306+
if response == response_options[0]:
307+
await hub.run(script_path, True)
308+
elif response == response_options[1]:
309+
await hub.download(script_path)
310+
else:
311+
exit(1)
292312

293313
finally:
294314
await hub.disconnect()
295315

296316

297317
class Flash(Tool):
298318

299-
300319
def add_parser(self, subparsers: argparse._SubParsersAction):
301320
parser = subparsers.add_parser(
302321
"flash", help="flash firmware on a LEGO Powered Up device"

pybricksdev/connections/pybricks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ def handle_power_button_press(status: StatusFlag):
714714
if status.value & StatusFlag.POWER_BUTTON_PRESSED:
715715
power_button_press_event.set()
716716

717-
with self.status_observable.subscribe(handle_power_button_press) and self.connection_state_observable.subscribe(handle_disconnect):
717+
with self.status_observable.subscribe(
718+
handle_power_button_press
719+
) and self.connection_state_observable.subscribe(handle_disconnect):
718720
done, pending = await asyncio.wait(
719721
{awaitable_task, power_button_press_task, disconnect_task},
720722
return_when=asyncio.FIRST_COMPLETED,
@@ -729,7 +731,7 @@ def handle_power_button_press(status: StatusFlag):
729731
raise RuntimeError("the hub was disconnected during operation")
730732
return awaitable_task.result()
731733

732-
async def _wait_for_user_program_stop(self, program_start_timeout = 1):
734+
async def _wait_for_user_program_stop(self, program_start_timeout=1):
733735
user_program_running: asyncio.Queue[bool] = asyncio.Queue()
734736

735737
with self.status_observable.pipe(

0 commit comments

Comments
 (0)