[pypy-commit] pypy py3k: test&fix for converting bytes to int
antocuni
noreply at buildbot.pypy.org
Thu Sep 6 18:00:22 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57183:5e75489d575a
Date: 2012-09-04 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/5e75489d575a/
Log: test&fix for converting bytes to int
diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -31,7 +31,8 @@
from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
return string_to_w_long(space, w_longtype,
unicode_to_decimal_w(space, w_value))
- elif space.isinstance_w(w_value, space.w_bytearray):
+ elif (space.isinstance_w(w_value, space.w_bytearray) or
+ space.isinstance_w(w_value, space.w_bytes)):
strvalue = space.bufferstr_w(w_value)
return string_to_w_long(space, w_longtype, strvalue.decode('latin-1'))
else:
diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -324,6 +324,9 @@
s = '\U0001D7CF\U0001D7CE' # 𝟏𝟎
assert int(s) == 10
+ def test_long_from_bytes(self):
+ assert int(b'1234') == 1234
+
def test_invalid_literal_message(self):
try:
int('hello àèìò')
More information about the pypy-commit
mailing list