-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: factor get_executable_args into helpers file
- Loading branch information
1 parent
1c8ce5c
commit e23b770
Showing
2 changed files
with
43 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Utility functions for handling keyboard input in curses | ||
systems | ||
""" | ||
|
||
from typing import TypeVar | ||
|
||
_T = TypeVar("_T") | ||
|
||
def get_executable_args( | ||
args: str, | ||
possible_args: dict[str, _T | int], | ||
) -> list[_T | int]: | ||
""" | ||
Convert `args` from a comma-space (, ) delimited string | ||
to separate python objects provided in `possible_args`. | ||
If `args` == None, return empty list | ||
Example `possible_args`: | ||
possible_args: dict[str, list | int | str] = { | ||
"lst": lst, | ||
"len(lst)": len(lst), | ||
"set_str": set_str, | ||
} | ||
""" | ||
params: list[_T | int] = [] | ||
for arg in args.split(", "): | ||
if arg.isdigit(): | ||
params.append(int(arg)) | ||
continue | ||
if arg != "None": | ||
params.append(possible_args[arg]) | ||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters