Mercurial > hg
comparison mercurial/__init__.py @ 43091:127cc1f72e70
py3: stop normalizing .encode()/.decode() arguments to unicode
Now that we don't byte transform string literals, we no longer need
this transform.
While we're here, we also drop some superfluous u'' prefix in existing
callers.
Differential Revision: https://phab.mercurial-scm.org/D7011
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 06 Oct 2019 17:27:51 -0400 |
parents | 1f339b503a40 |
children | c95b2f40db7c |
comparison
equal
deleted
inserted
replaced
43090:1f339b503a40 | 43091:127cc1f72e70 |
---|---|
164 ) and not _isop(i - 1, '.'): | 164 ) and not _isop(i - 1, '.'): |
165 arg1idx = _findargnofcall(1) | 165 arg1idx = _findargnofcall(1) |
166 if arg1idx is not None: | 166 if arg1idx is not None: |
167 _ensureunicode(arg1idx) | 167 _ensureunicode(arg1idx) |
168 | 168 |
169 # .encode() and .decode() on str/bytes/unicode don't accept | |
170 # byte strings on Python 3. | |
171 elif fn in ('encode', 'decode') and _isop(i - 1, '.'): | |
172 for argn in range(2): | |
173 argidx = _findargnofcall(argn) | |
174 if argidx is not None: | |
175 _ensureunicode(argidx) | |
176 | |
177 # It changes iteritems/values to items/values as they are not | 169 # It changes iteritems/values to items/values as they are not |
178 # present in Python 3 world. | 170 # present in Python 3 world. |
179 elif fn in ('iteritems', 'itervalues') and not ( | 171 elif fn in ('iteritems', 'itervalues') and not ( |
180 tokens[i - 1].type == token.NAME | 172 tokens[i - 1].type == token.NAME |
181 and tokens[i - 1].string == 'def' | 173 and tokens[i - 1].string == 'def' |
188 | 180 |
189 # Header to add to bytecode files. This MUST be changed when | 181 # Header to add to bytecode files. This MUST be changed when |
190 # ``replacetoken`` or any mechanism that changes semantics of module | 182 # ``replacetoken`` or any mechanism that changes semantics of module |
191 # loading is changed. Otherwise cached bytecode may get loaded without | 183 # loading is changed. Otherwise cached bytecode may get loaded without |
192 # the new transformation mechanisms applied. | 184 # the new transformation mechanisms applied. |
193 BYTECODEHEADER = b'HG\x00\x12' | 185 BYTECODEHEADER = b'HG\x00\x13' |
194 | 186 |
195 class hgloader(importlib.machinery.SourceFileLoader): | 187 class hgloader(importlib.machinery.SourceFileLoader): |
196 """Custom module loader that transforms source code. | 188 """Custom module loader that transforms source code. |
197 | 189 |
198 When the source code is converted to a code object, we transform | 190 When the source code is converted to a code object, we transform |