comparison mercurial/parser.py @ 48034:8655a77dce94

parser: force a `ValueError` to bytes before passing to `error.ParseError` I'm not sure what changed before pytype 09-09-2021 (from 04-15-2021), but this started getting flagged. I think there's a pytype bug here, because I don't see how `.lower()` can be getting called on a `ValueError` after it is forced to a byte string. That's suppressed for now to make progress. This fixes: File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: ValueError) Attributes of protocol Iterable[int] are not implemented on ValueError: __iter__ File "/mnt/c/Users/Matt/hg/mercurial/parser.py", line 219, in unescapestr: No attribute 'lower' on ValueError [attribute-error] In Union[ValueError, mercurial.pycompat.bytestr] Differential Revision: https://phab.mercurial-scm.org/D11471
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 20 Sep 2021 10:59:26 -0400
parents d4ba4d51f85f
children 6000f5b25c9b
comparison
equal deleted inserted replaced
48033:ae79611e3115 48034:8655a77dce94
19 from __future__ import absolute_import, print_function 19 from __future__ import absolute_import, print_function
20 20
21 from .i18n import _ 21 from .i18n import _
22 from . import ( 22 from . import (
23 error, 23 error,
24 pycompat,
25 util, 24 util,
26 ) 25 )
27 from .utils import stringutil 26 from .utils import stringutil
28 27
29 28
214 def unescapestr(s): 213 def unescapestr(s):
215 try: 214 try:
216 return stringutil.unescapestr(s) 215 return stringutil.unescapestr(s)
217 except ValueError as e: 216 except ValueError as e:
218 # mangle Python's exception into our format 217 # mangle Python's exception into our format
219 raise error.ParseError(pycompat.bytestr(e).lower()) 218 # TODO: remove this suppression. For some reason, pytype 2021.09.09
219 # thinks .lower() is being called on Union[ValueError, bytes].
220 # pytype: disable=attribute-error
221 raise error.ParseError(stringutil.forcebytestr(e).lower())
222 # pytype: enable=attribute-error
220 223
221 224
222 def _prettyformat(tree, leafnodes, level, lines): 225 def _prettyformat(tree, leafnodes, level, lines):
223 if not isinstance(tree, tuple): 226 if not isinstance(tree, tuple):
224 lines.append((level, stringutil.pprint(tree))) 227 lines.append((level, stringutil.pprint(tree)))