comparison mercurial/utils/stringutil.py @ 49648:9be765b82a90

typing: minor tweaks to allow updating to pytype 2022.11.18
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 23 Nov 2022 11:22:22 -0500
parents bbbb5213d043
children 493034cc3265
comparison
equal deleted inserted replaced
49646:2a70d1fc70c4 49648:9be765b82a90
721 # "bytes" is also a typing shortcut for bytes, bytearray, and memoryview 721 # "bytes" is also a typing shortcut for bytes, bytearray, and memoryview
722 if isinstance(s, memoryview): 722 if isinstance(s, memoryview):
723 s = bytes(s) 723 s = bytes(s)
724 # call underlying function of s.encode('string_escape') directly for 724 # call underlying function of s.encode('string_escape') directly for
725 # Python 3 compatibility 725 # Python 3 compatibility
726 # pytype: disable=bad-return-type
726 return codecs.escape_encode(s)[0] # pytype: disable=module-attr 727 return codecs.escape_encode(s)[0] # pytype: disable=module-attr
728 # pytype: enable=bad-return-type
727 729
728 730
729 def unescapestr(s: bytes) -> bytes: 731 def unescapestr(s: bytes) -> bytes:
732 # pytype: disable=bad-return-type
730 return codecs.escape_decode(s)[0] # pytype: disable=module-attr 733 return codecs.escape_decode(s)[0] # pytype: disable=module-attr
734 # pytype: enable=bad-return-type
731 735
732 736
733 def forcebytestr(obj): 737 def forcebytestr(obj):
734 """Portably format an arbitrary object (e.g. exception) into a byte 738 """Portably format an arbitrary object (e.g. exception) into a byte
735 string.""" 739 string."""