##// END OF EJS Templates
typing: add type hints to the `charencode` module...
Matt Harbison -
r52615:43adbe03 default
parent child Browse files
Show More
@@ -40,6 +40,16 asciiupper = charencode.asciiupper
40 40
41 41 unichr = chr
42 42
43 if typing.TYPE_CHECKING:
44 # TODO: make a stub file for .cext.charencode, and import here
45 from .pure.charencode import (
46 asciilower,
47 asciiupper,
48 isasciistr,
49 jsonescapeu8fast as _jsonescapeu8fast,
50 )
51
52
43 53 # These unicode characters are ignored by HFS+ (Apple Technote 1150,
44 54 # "Unicode Subtleties"), so we need to ignore them in some places for
45 55 # sanity.
@@ -524,7 +534,7 class normcasespecs:
524 534 other = 0
525 535
526 536
527 def jsonescape(s: Any, paranoid: Any = False) -> Any:
537 def jsonescape(s: bytes, paranoid: bool = False) -> bytes:
528 538 """returns a string suitable for JSON
529 539
530 540 JSON is problematic for us because it doesn't support non-Unicode
@@ -11,7 +11,7 import array
11 11 from .. import pycompat
12 12
13 13
14 def isasciistr(s):
14 def isasciistr(s: bytes) -> bool:
15 15 try:
16 16 s.decode('ascii')
17 17 return True
@@ -19,7 +19,7 def isasciistr(s):
19 19 return False
20 20
21 21
22 def asciilower(s):
22 def asciilower(s: bytes) -> bytes:
23 23 """convert a string to lowercase if ASCII
24 24
25 25 Raises UnicodeDecodeError if non-ASCII characters are found."""
@@ -27,7 +27,7 def asciilower(s):
27 27 return s.lower()
28 28
29 29
30 def asciiupper(s):
30 def asciiupper(s: bytes) -> bytes:
31 31 """convert a string to uppercase if ASCII
32 32
33 33 Raises UnicodeDecodeError if non-ASCII characters are found."""
@@ -52,7 +52,7 def asciiupper(s):
52 52 _jsonmap.extend(pycompat.bytechr(x) for x in range(128, 256))
53 53
54 54
55 def jsonescapeu8fast(u8chars, paranoid):
55 def jsonescapeu8fast(u8chars: bytes, paranoid: bool) -> bytes:
56 56 """Convert a UTF-8 byte string to JSON-escaped form (fast path)
57 57
58 58 Raises ValueError if non-ASCII characters have to be escaped.
@@ -70,7 +70,7 def jsonescapeu8fast(u8chars, paranoid):
70 70 _utf8strict = r'surrogatepass'
71 71
72 72
73 def jsonescapeu8fallback(u8chars, paranoid):
73 def jsonescapeu8fallback(u8chars: bytes, paranoid: bool) -> bytes:
74 74 """Convert a UTF-8 byte string to JSON-escaped form (slow path)
75 75
76 76 Escapes all non-ASCII characters no matter if paranoid is False.
General Comments 0
You need to be logged in to leave comments. Login now