Author: Simon Cross <[email protected]>
Branch: remove-string-smm
Changeset: r62627:67ef049cda7e
Date: 2013-03-22 02:08 +0200
http://bitbucket.org/pypy/pypy/changeset/67ef049cda7e/

Log:    Re-implement bytearray.remove.

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
@@ -397,14 +397,6 @@
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_isspace__String(space, w_str)
 
-def bytearray_remove__Bytearray_ANY(space, w_bytearray, w_char):
-    char = space.int_w(space.index(w_char))
-    try:
-        result = w_bytearray.data.remove(chr(char))
-    except ValueError:
-        raise OperationError(space.w_ValueError, space.wrap(
-            "value not found in bytearray"))
-
 def bytearray_reverse__Bytearray(space, w_bytearray):
     w_bytearray.data.reverse()
     return space.w_None
diff --git a/pypy/objspace/std/bytearraytype.py 
b/pypy/objspace/std/bytearraytype.py
--- a/pypy/objspace/std/bytearraytype.py
+++ b/pypy/objspace/std/bytearraytype.py
@@ -56,9 +56,19 @@
     return space.wrap(ord(result))
 
 
-bytearray_remove  = SMM('remove', 2,
-                    doc="B.remove(int) -> None\n\n"
-                    "Remove the first occurance of a value in B.")
+@unwrap_spec(w_self=W_Root)
+def bytearray_remove(w_self, space, w_index):
+    """B.remove(int) -> None
+
+    Remove the first occurance of a value in B.
+    """
+    val = space.int_w(space.index(w_index))
+    try:
+        w_self.data.remove(chr(val))
+    except ValueError:
+        raise OperationError(space.w_ValueError, space.wrap(
+            "value not found in bytearray"))
+
 
 bytearray_reverse  = SMM('reverse', 1,
                     doc="B.reverse() -> None\n\n"
@@ -200,8 +210,9 @@
     __hash__ = None,
     __reduce__ = interp2app(descr_bytearray__reduce__),
     fromhex = interp2app(descr_fromhex, as_classmethod=True),
-    insert = interp2app(bytearray_insert),
-    pop = interp2app(bytearray_pop),
+    insert=interp2app(bytearray_insert),
+    pop=interp2app(bytearray_pop),
+    remove=interp2app(bytearray_remove),
     **bytearray_interface_methods()
     )
 bytearray_typedef.registermethods(globals())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to