equal
deleted
inserted
replaced
18 pycompat, |
18 pycompat, |
19 ) |
19 ) |
20 |
20 |
21 from .pure import charencode as charencodepure |
21 from .pure import charencode as charencodepure |
22 |
22 |
|
23 _TYPE_CHECKING = False |
|
24 |
23 if not globals(): # hide this from non-pytype users |
25 if not globals(): # hide this from non-pytype users |
24 from typing import ( |
26 from typing import ( |
25 Any, |
27 Any, |
26 Callable, |
28 Callable, |
27 List, |
29 List, |
|
30 TYPE_CHECKING as _TYPE_CHECKING, |
28 Text, |
31 Text, |
29 Type, |
32 Type, |
30 TypeVar, |
33 TypeVar, |
31 Union, |
34 Union, |
32 ) |
35 ) |
115 class localstr(bytes): |
118 class localstr(bytes): |
116 '''This class allows strings that are unmodified to be |
119 '''This class allows strings that are unmodified to be |
117 round-tripped to the local encoding and back''' |
120 round-tripped to the local encoding and back''' |
118 |
121 |
119 def __new__(cls, u, l): |
122 def __new__(cls, u, l): |
120 # type: (Type[_Tlocalstr], bytes, bytes) -> _Tlocalstr |
|
121 s = bytes.__new__(cls, l) |
123 s = bytes.__new__(cls, l) |
122 s._utf8 = u |
124 s._utf8 = u |
123 return s |
125 return s |
|
126 |
|
127 if _TYPE_CHECKING: |
|
128 # pseudo implementation to help pytype see localstr() constructor |
|
129 def __init__(self, u, l): |
|
130 # type: (bytes, bytes) -> None |
|
131 super(localstr, self).__init__(l) |
|
132 self._utf8 = u |
124 |
133 |
125 def __hash__(self): |
134 def __hash__(self): |
126 return hash(self._utf8) # avoid collisions in local string space |
135 return hash(self._utf8) # avoid collisions in local string space |
127 |
136 |
128 |
137 |