mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
py3: don't assert on byte types in python 2
Summary: We don't have confidence that python 2 is only using bytes (vs unicode or other byte-like objects). These asserts break users, so let's disable them except for in tests. We should uncover issues here as we port to python 3. Reviewed By: xavierd Differential Revision: D19819699 fbshipit-source-id: 9e3a9c34e7661fac4db9ee2a79f65be3d5e48cb3
This commit is contained in:
parent
f918387338
commit
2a975077f5
@ -54,6 +54,19 @@ def identity(a):
|
||||
return a
|
||||
|
||||
|
||||
# Copied from util.py to avoid pycompat depending on Mercurial modules
|
||||
if "TESTTMP" in os.environ or "testutil" in sys.modules:
|
||||
|
||||
def istest():
|
||||
return True
|
||||
|
||||
|
||||
else:
|
||||
|
||||
def istest():
|
||||
return False
|
||||
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
import builtins
|
||||
import functools
|
||||
@ -165,12 +178,15 @@ else:
|
||||
|
||||
def encodeutf8(s):
|
||||
# type: (bytes) -> bytes
|
||||
assert isinstance(s, bytes)
|
||||
if istest():
|
||||
assert isinstance(s, bytes)
|
||||
|
||||
return s
|
||||
|
||||
def decodeutf8(s, errors="strict"):
|
||||
# type: (bytes, str) -> bytes
|
||||
assert isinstance(s, bytes)
|
||||
if istest():
|
||||
assert isinstance(s, bytes)
|
||||
return s
|
||||
|
||||
def iteritems(s):
|
||||
|
Loading…
Reference in New Issue
Block a user