Mercurial > public > mercurial-scm > hg
comparison mercurial/encoding.py @ 48007:28c62f83b652
encoding: force a few Errors to bytes before passing to `error.Abort`
I'm not sure what changed before pytype 09-09-2021 (from 04-15-2021), but these
started getting flagged. PyCharm also flagged these. This fixes the following:
File "/mnt/c/Users/Matt/hg/mercurial/encoding.py", line 243, in fromlocal: Function Abort.__init__ was called with the wrong arguments [wrong-arg-types]
Expected: (self, message: Union[bytearray, bytes, memoryview], ...)
Actually passed: (self, message: LookupError, ...)
File "/mnt/c/Users/Matt/hg/mercurial/encoding.py", line 309, in lower: Function Abort.__init__ was called with the wrong arguments [wrong-arg-types]
Expected: (self, message: Union[bytearray, bytes, memoryview], ...)
Actually passed: (self, message: LookupError, ...)
File "/mnt/c/Users/Matt/hg/mercurial/encoding.py", line 336, in upperfallback: Function Abort.__init__ was called with the wrong arguments [wrong-arg-types]
Expected: (self, message: Union[bytearray, bytes, memoryview], ...)
Actually passed: (self, message: LookupError, ...)
Called from (traceback):
line 391, in current file
line 348, in get
line 318, in upper
Differential Revision: https://phab.mercurial-scm.org/D11467
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 20 Sep 2021 10:42:38 -0400 |
parents | d6ee6456bd5f |
children | f1ed5c304f45 |
comparison
equal
deleted
inserted
replaced
48006:1fda8c9358ce | 48007:28c62f83b652 |
---|---|
238 sub = s[max(0, inst.start - 10) : inst.start + 10] | 238 sub = s[max(0, inst.start - 10) : inst.start + 10] |
239 raise error.Abort( | 239 raise error.Abort( |
240 b"decoding near '%s': %s!" % (sub, pycompat.bytestr(inst)) | 240 b"decoding near '%s': %s!" % (sub, pycompat.bytestr(inst)) |
241 ) | 241 ) |
242 except LookupError as k: | 242 except LookupError as k: |
243 raise error.Abort(k, hint=b"please check your locale settings") | 243 raise error.Abort( |
244 pycompat.bytestr(k), hint=b"please check your locale settings" | |
245 ) | |
244 | 246 |
245 | 247 |
246 def unitolocal(u): | 248 def unitolocal(u): |
247 # type: (Text) -> bytes | 249 # type: (Text) -> bytes |
248 """Convert a unicode string to a byte string of local encoding""" | 250 """Convert a unicode string to a byte string of local encoding""" |
304 return s # preserve localstring | 306 return s # preserve localstring |
305 return lu.encode(_sysstr(encoding)) | 307 return lu.encode(_sysstr(encoding)) |
306 except UnicodeError: | 308 except UnicodeError: |
307 return s.lower() # we don't know how to fold this except in ASCII | 309 return s.lower() # we don't know how to fold this except in ASCII |
308 except LookupError as k: | 310 except LookupError as k: |
309 raise error.Abort(k, hint=b"please check your locale settings") | 311 raise error.Abort( |
312 pycompat.bytestr(k), hint=b"please check your locale settings" | |
313 ) | |
310 | 314 |
311 | 315 |
312 def upper(s): | 316 def upper(s): |
313 # type: (bytes) -> bytes | 317 # type: (bytes) -> bytes |
314 """best-effort encoding-aware case-folding of local string s""" | 318 """best-effort encoding-aware case-folding of local string s""" |
331 return s # preserve localstring | 335 return s # preserve localstring |
332 return uu.encode(_sysstr(encoding)) | 336 return uu.encode(_sysstr(encoding)) |
333 except UnicodeError: | 337 except UnicodeError: |
334 return s.upper() # we don't know how to fold this except in ASCII | 338 return s.upper() # we don't know how to fold this except in ASCII |
335 except LookupError as k: | 339 except LookupError as k: |
336 raise error.Abort(k, hint=b"please check your locale settings") | 340 raise error.Abort( |
341 pycompat.bytestr(k), hint=b"please check your locale settings" | |
342 ) | |
337 | 343 |
338 | 344 |
339 if not _nativeenviron: | 345 if not _nativeenviron: |
340 # now encoding and helper functions are available, recreate the environ | 346 # now encoding and helper functions are available, recreate the environ |
341 # dict to be exported to other modules | 347 # dict to be exported to other modules |