Skip to content

Commit

Permalink
Enforce stricter typing through Popen Protocol definition (#829)
Browse files Browse the repository at this point in the history
Summary:
## No functional changes
Explicitly list out the list of Popen API that's used in the LocalScheduler class to enforce stricter typing.

Differential Revision: D53788269

Co-authored-by: Cheng Ni <[email protected]>
  • Loading branch information
manav-a and cniii authored Feb 29, 2024
1 parent e0efca2 commit 42de5b5
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions torchx/schedulers/local_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Iterable,
List,
Optional,
Protocol,
TextIO,
Tuple,
)
Expand Down Expand Up @@ -262,6 +263,25 @@ def get_entrypoint(self, img_root: str, role: Role) -> str:
RoleName = str


class PopenProtocol(Protocol):
@property
def pid(self) -> int:
...

@property
def returncode(self) -> int:
...

def wait(self, timeout: Optional[float] = None) -> int:
...

def poll(self) -> Optional[int]:
...

def kill(self) -> None:
...


@dataclass
class _LocalReplica:
"""
Expand All @@ -270,8 +290,7 @@ class _LocalReplica:

role_name: RoleName
replica_id: int
# pyre-fixme[24]: Generic type `subprocess.Popen` expects 1 type parameter.
proc: subprocess.Popen
proc: PopenProtocol

# IO streams:
# None means no log_dir (out to console)
Expand Down

0 comments on commit 42de5b5

Please sign in to comment.