Skip to content

Commit

Permalink
type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Feb 12, 2024
1 parent 9bf336b commit 014508a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion suby/errors.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from suby.subprocess_result import SubprocessResult


class RunningCommandError(Exception):
pass
def __init__(self, message: str, subprocess_result: SubprocessResult) -> None:
self.result = subprocess_result
super().__init__(self, message)
13 changes: 2 additions & 11 deletions suby/proxy_module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from time import sleep
from dataclasses import dataclass, field
from threading import Thread, Lock
from subprocess import Popen, PIPE
from typing import List, Callable, Union, Optional, Any
Expand All @@ -10,14 +9,7 @@
from cantok import AbstractToken, SimpleToken, TimeoutToken, CancellationError

from suby.errors import RunningCommandError


@dataclass
class SubprocessResult:
stdout: Optional[str] = None
stderr: Optional[str] = None
returncode: Optional[int] = None
killed_by_token: bool = False
from suby.subprocess_result import SubprocessResult


class ProxyModule(sys.modules[__name__].__class__): # type: ignore[misc]
Expand Down Expand Up @@ -66,8 +58,7 @@ def __call__(self, *arguments: str, catch_output: bool = False, logger: LoggerPr
else:
message = f'Error when executing the command "{arguments_string_representation}".'
logger.error(message)
exception = RunningCommandError(message)
exception.result = result
exception = RunningCommandError(message, result)
raise exception

else:
Expand Down
10 changes: 10 additions & 0 deletions suby/subprocess_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass
from typing import Optional


@dataclass
class SubprocessResult:
stdout: Optional[str] = None
stderr: Optional[str] = None
returncode: Optional[int] = None
killed_by_token: bool = False

0 comments on commit 014508a

Please sign in to comment.