from datetime import datetime
from typing import Type
[docs]class ExitCode(int):
"""The code returned to a parent process by an executable.
Examples:
>>> from subprocess import call
>>> exit_code = ExitCode(call('ls'))
>>> exit_code.is_ok()
True
"""
def __new__(cls, exit_code: int) -> Type['ExitCode']:
"""Make a new :class:`ExitCode`."""
cls._code = exit_code
return super().__new__(cls, exit_code) # type: ignore
[docs] def is_ok(self) -> bool:
"""Is this code zero."""
return self._code == 0
def __repr__(self) -> str:
"""Represent this object."""
return f'{self.__class__.__qualname__}({self._code})'