mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[robotpy] Mirror robotpy's commands-v2 (#8369)
Project import generated by Copybara. GitOrigin-RevId: 715c8e8372d936f447f2937aab6b1a22dc619126
This commit is contained in:
25
commandsv2/src/main/python/commands2/util.py
Normal file
25
commandsv2/src/main/python/commands2/util.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# notrack
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, List, Tuple, Union
|
||||
|
||||
from .command import Command
|
||||
|
||||
|
||||
def flatten_args_commands(
|
||||
*commands: Union[Command, Iterable[Command]]
|
||||
) -> Tuple[Command, ...]:
|
||||
flattened_commands: List[Command] = []
|
||||
for command in commands:
|
||||
if isinstance(command, Command):
|
||||
flattened_commands.append(command)
|
||||
elif isinstance(command, Iterable):
|
||||
flattened_commands.extend(flatten_args_commands(*command))
|
||||
return tuple(flattened_commands)
|
||||
|
||||
|
||||
def format_args_kwargs(*args, **kwargs) -> str:
|
||||
return ", ".join(
|
||||
[repr(arg) for arg in args]
|
||||
+ [f"{key}={repr(value)}" for key, value in kwargs.items()]
|
||||
)
|
||||
Reference in New Issue
Block a user