Skip to content

Commit abf19bb

Browse files
committed
Putative fix for issue #193
1 parent 956817c commit abf19bb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/future/types/newbytes.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections import Iterable
99
from numbers import Integral
1010
import string
11+
import copy
1112

1213
from future.utils import istext, isbytes, PY3, with_metaclass
1314
from future.types import no, issubset
@@ -49,7 +50,6 @@ def __new__(cls, *args, **kwargs):
4950
- any object implementing the buffer API.
5051
- an integer
5152
"""
52-
5353
encoding = None
5454
errors = None
5555

@@ -112,7 +112,15 @@ def __new__(cls, *args, **kwargs):
112112
value = b'\x00' * args[0]
113113
else:
114114
value = args[0]
115-
return super(newbytes, cls).__new__(cls, value)
115+
if type(value) == newbytes:
116+
# Above we use type(...) rather than isinstance(...) because the
117+
# newbytes metaclass overrides __instancecheck__.
118+
# oldbytes(value) gives the wrong thing on Py2: the same
119+
# result as str(value) on Py3, e.g. "b'abc'". (Issue #193).
120+
# So we handle this case separately:
121+
return copy.copy(value)
122+
else:
123+
return super(newbytes, cls).__new__(cls, value)
116124

117125
def __repr__(self):
118126
return 'b' + super(newbytes, self).__repr__()

0 commit comments

Comments
 (0)