Simple custom stand-in for SystemExit. Replaces scattered sys.exit calls, improves testability, allows one to catch an exit request without intercepting real SystemExits (typically an unfriendly thing to do, as most users calling `sys.exit` rather expect it to truly exit.)
| 205 | |
| 206 | |
| 207 | class Exit(Exception): |
| 208 | """ |
| 209 | Simple custom stand-in for SystemExit. |
| 210 | |
| 211 | Replaces scattered sys.exit calls, improves testability, allows one to |
| 212 | catch an exit request without intercepting real SystemExits (typically an |
| 213 | unfriendly thing to do, as most users calling `sys.exit` rather expect it |
| 214 | to truly exit.) |
| 215 | |
| 216 | Defaults to a non-printing, exit-0 friendly termination behavior if the |
| 217 | exception is uncaught. |
| 218 | |
| 219 | If ``code`` (an int) given, that code is used to exit. |
| 220 | |
| 221 | If ``message`` (a string) given, it is printed to standard error, and the |
| 222 | program exits with code ``1`` by default (unless overridden by also giving |
| 223 | ``code`` explicitly.) |
| 224 | |
| 225 | .. versionadded:: 1.0 |
| 226 | """ |
| 227 | |
| 228 | def __init__( |
| 229 | self, message: Optional[str] = None, code: Optional[int] = None |
| 230 | ) -> None: |
| 231 | self.message = message |
| 232 | self._code = code |
| 233 | |
| 234 | @property |
| 235 | def code(self) -> int: |
| 236 | if self._code is not None: |
| 237 | return self._code |
| 238 | return 1 if self.message else 0 |
| 239 | |
| 240 | |
| 241 | class PlatformError(Exception): |
no outgoing calls
no test coverage detected
searching dependent graphs…