18
18
19
19
# typing --------------------------------------------------------------------
20
20
21
- from typing import IO , Any , AnyStr , Dict , Optional , Type , Union
21
+ from typing import (
22
+ Any ,
23
+ AnyStr ,
24
+ Dict ,
25
+ IO ,
26
+ Optional ,
27
+ Type ,
28
+ Union ,
29
+ overload ,
30
+ )
22
31
from git .types import TBD
23
32
24
33
# ---------------------------------------------------------------------------
30
39
defenc = sys .getfilesystemencoding ()
31
40
32
41
42
+ @overload
43
+ def safe_decode (s : None ) -> None : ...
44
+
45
+ @overload
46
+ def safe_decode (s : Union [IO [str ], AnyStr ]) -> str : ...
47
+
33
48
def safe_decode (s : Union [IO [str ], AnyStr , None ]) -> Optional [str ]:
34
49
"""Safely decodes a binary string to unicode"""
35
50
if isinstance (s , str ):
@@ -42,6 +57,12 @@ def safe_decode(s: Union[IO[str], AnyStr, None]) -> Optional[str]:
42
57
raise TypeError ('Expected bytes or text, but got %r' % (s ,))
43
58
44
59
60
+ @overload
61
+ def safe_encode (s : None ) -> None : ...
62
+
63
+ @overload
64
+ def safe_encode (s : AnyStr ) -> bytes : ...
65
+
45
66
def safe_encode (s : Optional [AnyStr ]) -> Optional [bytes ]:
46
67
"""Safely encodes a binary string to unicode"""
47
68
if isinstance (s , str ):
@@ -54,6 +75,12 @@ def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]:
54
75
raise TypeError ('Expected bytes or text, but got %r' % (s ,))
55
76
56
77
78
+ @overload
79
+ def win_encode (s : None ) -> None : ...
80
+
81
+ @overload
82
+ def win_encode (s : AnyStr ) -> bytes : ...
83
+
57
84
def win_encode (s : Optional [AnyStr ]) -> Optional [bytes ]:
58
85
"""Encode unicodes for process arguments on Windows."""
59
86
if isinstance (s , str ):
@@ -65,7 +92,6 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
65
92
return None
66
93
67
94
68
-
69
95
def with_metaclass (meta : Type [Any ], * bases : Any ) -> 'metaclass' : # type: ignore ## mypy cannot understand dynamic class creation
70
96
"""copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""
71
97
0 commit comments