Skip to content

Commit

Permalink
Add NamedTuple for Tuple from parsing AppHandle (#800)
Browse files Browse the repository at this point in the history
Summary: Stricter types and better IDE hints via namedtuple over tuple

Differential Revision: D52092870
  • Loading branch information
bobyangyf authored Dec 18, 2023
1 parent c3868c1 commit 9d5e3c5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions torchx/specs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Iterator,
List,
Mapping,
NamedTuple,
Optional,
Pattern,
Tuple,
Expand Down Expand Up @@ -970,6 +971,16 @@ def __init__(self, scheduler_backend: str) -> None:
AppHandle = str


class ParsedAppHandle(NamedTuple):
"""
Individual accessible components of the `AppHandle`
"""

scheduler_backend: str
session_name: str
app_id: str


class UnknownAppException(Exception):
"""
Raised by ``Session`` APIs when either the application does not
Expand All @@ -983,7 +994,7 @@ def __init__(self, app_handle: "AppHandle") -> None:
)


def parse_app_handle(app_handle: AppHandle) -> Tuple[str, str, str]:
def parse_app_handle(app_handle: AppHandle) -> ParsedAppHandle:
"""
parses the app handle into ```(scheduler_backend, session_name, and app_id)```
"""
Expand All @@ -997,4 +1008,4 @@ def parse_app_handle(app_handle: AppHandle) -> Tuple[str, str, str]:
if not match:
raise MalformedAppHandleException(app_handle)
gd = match.groupdict()
return gd["scheduler_backend"], gd["session_name"], gd["app_id"]
return ParsedAppHandle(gd["scheduler_backend"], gd["session_name"], gd["app_id"])

0 comments on commit 9d5e3c5

Please sign in to comment.