comparison mercurial/utils/stringutil.py @ 48518:dcdecec401ca

pytype: stop excluding stringutil.py This fixes the following: File "/mnt/c/Users/Matt/hg/mercurial/utils/stringutil.py", line 267, in prettyrepr: Function bytes.startswith expects 2 arg(s), got 3 [wrong-arg-count] Expected: (self, prefix) Actually passed: (self, prefix, _) File "/mnt/c/Users/Matt/hg/mercurial/utils/stringutil.py", line 695, in escapestr: No attribute 'escape_encode' on module 'codecs' [module-attr] File "/mnt/c/Users/Matt/hg/mercurial/utils/stringutil.py", line 699, in unescapestr: No attribute 'escape_decode' on module 'codecs' [module-attr] Differential Revision: https://phab.mercurial-scm.org/D11918
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 13 Dec 2021 14:43:10 -0500
parents b0e92313107e
children 6000f5b25c9b
comparison
equal deleted inserted replaced
48517:3444e0b39c30 48518:dcdecec401ca
262 # p0 p1 q0 q1 262 # p0 p1 q0 q1
263 q0 = -1 263 q0 = -1
264 q1 = rs.find(b'<', p1 + 1) 264 q1 = rs.find(b'<', p1 + 1)
265 if q1 < 0: 265 if q1 < 0:
266 q1 = len(rs) 266 q1 = len(rs)
267 # pytype: disable=wrong-arg-count
268 # TODO: figure out why pytype doesn't recognize the optional start
269 # arg
267 elif q1 > p1 + 1 and rs.startswith(b'=', q1 - 1): 270 elif q1 > p1 + 1 and rs.startswith(b'=', q1 - 1):
271 # pytype: enable=wrong-arg-count
268 # backtrack for ' field=<' 272 # backtrack for ' field=<'
269 q0 = rs.rfind(b' ', p1 + 1, q1 - 1) 273 q0 = rs.rfind(b' ', p1 + 1, q1 - 1)
270 if q0 < 0: 274 if q0 < 0:
271 q0 = q1 275 q0 = q1
272 else: 276 else:
690 def escapestr(s): 694 def escapestr(s):
691 if isinstance(s, memoryview): 695 if isinstance(s, memoryview):
692 s = bytes(s) 696 s = bytes(s)
693 # call underlying function of s.encode('string_escape') directly for 697 # call underlying function of s.encode('string_escape') directly for
694 # Python 3 compatibility 698 # Python 3 compatibility
695 return codecs.escape_encode(s)[0] 699 return codecs.escape_encode(s)[0] # pytype: disable=module-attr
696 700
697 701
698 def unescapestr(s): 702 def unescapestr(s):
699 return codecs.escape_decode(s)[0] 703 return codecs.escape_decode(s)[0] # pytype: disable=module-attr
700 704
701 705
702 def forcebytestr(obj): 706 def forcebytestr(obj):
703 """Portably format an arbitrary object (e.g. exception) into a byte 707 """Portably format an arbitrary object (e.g. exception) into a byte
704 string.""" 708 string."""