comparison mercurial/error.py @ 46681:ae62ab82a345 stable

typing: ensure that error.Abort is given bytes There's a bunch more typing to be done here, but the list of things to fix is already long, and I know there are instances where this is being used incorrectly. Differential Revision: https://phab.mercurial-scm.org/D10166
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 11 Mar 2021 21:25:28 -0500
parents 89a2afe31e82
children e2f7b2695ba1
comparison
equal deleted inserted replaced
46680:6595e22048fe 46681:ae62ab82a345
15 15
16 import difflib 16 import difflib
17 17
18 # Do not import anything but pycompat here, please 18 # Do not import anything but pycompat here, please
19 from . import pycompat 19 from . import pycompat
20
21 if pycompat.TYPE_CHECKING:
22 from typing import (
23 Optional,
24 )
20 25
21 26
22 def _tobytes(exc): 27 def _tobytes(exc):
23 """Byte-stringify exception in the same way as BaseException_str()""" 28 """Byte-stringify exception in the same way as BaseException_str()"""
24 if not exc.args: 29 if not exc.args:
167 172
168 class Abort(Hint, Exception): 173 class Abort(Hint, Exception):
169 """Raised if a command needs to print an error and exit.""" 174 """Raised if a command needs to print an error and exit."""
170 175
171 def __init__(self, message, hint=None): 176 def __init__(self, message, hint=None):
177 # type: (bytes, Optional[bytes]) -> None
172 self.message = message 178 self.message = message
173 self.hint = hint 179 self.hint = hint
174 # Pass the message into the Exception constructor to help extensions 180 # Pass the message into the Exception constructor to help extensions
175 # that look for exc.args[0]. 181 # that look for exc.args[0].
176 Exception.__init__(self, message) 182 Exception.__init__(self, message)