@@ -566,7 +566,7 @@ async def download(self, script_path: str) -> None:
566566
567567 async def run (
568568 self ,
569- py_path : Optional [ str ] = None ,
569+ program : str | int ,
570570 wait : bool = True ,
571571 print_output : bool = True ,
572572 line_handler : bool = True ,
@@ -575,8 +575,8 @@ async def run(
575575 Compiles and runs a user program.
576576
577577 Args:
578- py_path : The path to the .py file to compile. If None, runs a
579- previously downloaded program.
578+ program : The path to the .py file to compile. If an integer is
579+ given, runs a slot or builtin program with that identifier .
580580 wait: If true, wait for the user program to stop before returning.
581581 print_output: If true, echo stdout of the hub to ``sys.stdout``.
582582 line_handler: If true enable hub stdout line handler features.
@@ -592,24 +592,23 @@ async def run(
592592 self .print_output = print_output
593593 self ._enable_line_handler = line_handler
594594 self .script_dir = os .getcwd ()
595- if py_path is not None :
596- self .script_dir , _ = os .path .split (py_path )
595+ if isinstance ( program , str ) :
596+ self .script_dir , _ = os .path .split (program )
597597
598598 # maintain compatibility with older firmware (Pybricks profile < 1.2.0).
599599 if self ._mpy_abi_version :
600- if py_path is None :
600+ if not isinstance ( program , str ) :
601601 raise RuntimeError (
602- "Hub does not support running stored program. Provide a py_path to run"
602+ "Hub does not support running stored program. Provide a path to run"
603603 )
604- await self ._legacy_run (py_path , wait )
604+ await self ._legacy_run (program , wait )
605605 return
606606
607- # Download the program if a path is provided
608- if py_path is not None :
609- await self .download (py_path )
610-
611- # Start the program
612- await self .start_user_program ()
607+ if isinstance (program , str ):
608+ await self .download (program )
609+ await self .start_user_program ()
610+ else :
611+ await self .start_user_program (program )
613612
614613 if wait :
615614 await self ._wait_for_user_program_stop ()
0 commit comments