Author: Simon Cross <[email protected]>
Branch: remove-string-smm
Changeset: r62623:47ef3c341a14
Date: 2013-03-22 01:53 +0200
http://bitbucket.org/pypy/pypy/changeset/47ef3c341a14/

Log:    Re-implement bytearray.pop.

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,18 +397,6 @@
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_isspace__String(space, w_str)
 
-def bytearray_pop__Bytearray_Int(space, w_bytearray, w_idx):
-    index = space.int_w(w_idx)
-    try:
-        result = w_bytearray.data.pop(index)
-    except IndexError:
-        if not w_bytearray.data:
-            raise OperationError(space.w_IndexError, space.wrap(
-                "pop from empty bytearray"))
-        raise OperationError(space.w_IndexError, space.wrap(
-            "pop index out of range"))
-    return space.wrap(ord(result))
-
 def bytearray_remove__Bytearray_ANY(space, w_bytearray, w_char):
     char = space.int_w(space.index(w_char))
     try:
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
@@ -38,10 +38,23 @@
     return space.w_None
 
 
-bytearray_pop  = SMM('pop', 2, defaults=(-1,),
-                    doc="B.pop([index]) -> int\n\nRemove and return a "
-                    "single item from B. If no index\nargument is given, "
-                    "will pop the last value.")
+@unwrap_spec(w_self=W_Root, index=int)
+def bytearray_pop(w_self, space, index=-1):
+    """B.pop([index]) -> int
+
+    Remove and return a single item from B. If no index
+    argument is given, will pop the last value.
+    """
+    try:
+        result = w_self.data.pop(index)
+    except IndexError:
+        if not w_self.data:
+            raise OperationError(space.w_IndexError, space.wrap(
+                "pop from empty bytearray"))
+        raise OperationError(space.w_IndexError, space.wrap(
+            "pop index out of range"))
+    return space.wrap(ord(result))
+
 
 bytearray_remove  = SMM('remove', 2,
                     doc="B.remove(int) -> None\n\n"
@@ -188,6 +201,7 @@
     __reduce__ = interp2app(descr_bytearray__reduce__),
     fromhex = interp2app(descr_fromhex, as_classmethod=True),
     insert = interp2app(bytearray_insert),
+    pop = interp2app(bytearray_pop),
     **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