[pypy-commit] pypy default: Merged in kostialopuhin/pypy (pull request #79)
fijal
noreply at buildbot.pypy.org
Fri Oct 26 10:50:14 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r58430:58260cf95e05
Date: 2012-10-26 10:49 +0200
http://bitbucket.org/pypy/pypy/changeset/58260cf95e05/
Log: Merged in kostialopuhin/pypy (pull request #79)
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -13,6 +13,8 @@
from pypy.objspace.std.listtype import get_list_index
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.strutil import ParseStringError
+from pypy.objspace.std.strutil import string_to_float
from pypy.objspace.std.tupleobject import W_TupleObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
from pypy.objspace.std import slicetype
@@ -81,6 +83,14 @@
data = makebytearraydata_w(space, w_source)
w_bytearray.data = data
+def float__Bytearray(space, w_bytearray):
+ try:
+ value = string_to_float(''.join(w_bytearray.data))
+ except ParseStringError, e:
+ raise OperationError(space.w_ValueError, space.wrap(e.msg))
+ else:
+ return space.wrap(value)
+
def len__Bytearray(space, w_bytearray):
result = len(w_bytearray.data)
return wrapint(space, result)
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -439,6 +439,14 @@
def test_int(self):
assert int(bytearray('-1234')) == -1234
+ def test_float(self):
+ assert float(bytearray(b'10.4')) == 10.4
+ assert float(bytearray('-1.7e-1')) == -1.7e-1
+ assert float(bytearray(u'.9e10', 'utf-8')) == .9e10
+ import math
+ assert math.isnan(float(bytearray('nan')))
+ raises(ValueError, float, bytearray('not_a_number'))
+
def test_reduce(self):
assert bytearray('caf\xe9').__reduce__() == (
bytearray, (u'caf\xe9', 'latin-1'), None)
More information about the pypy-commit
mailing list