Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r88971:fcf3ec196b93
Date: 2016-12-08 14:08 +0000
http://bitbucket.org/pypy/pypy/changeset/fcf3ec196b93/
Log: Add bytearray.__rmod__
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
@@ -488,6 +488,11 @@
def descr_mod(self, space, w_values):
return mod_format(space, self, w_values, fmt_type=FORMAT_BYTEARRAY)
+ def descr_rmod(self, space, w_value):
+ if not isinstance(w_value, W_BytearrayObject):
+ return space.w_NotImplemented
+ return mod_format(space, w_value, self, fmt_type=FORMAT_BYTEARRAY)
+
@staticmethod
def _iter_getitem_result(self, space, index):
assert isinstance(self, W_BytearrayObject)
@@ -671,7 +676,10 @@
"""x.__mul__(n) <==> x*n"""
def __mod__():
- """x.__mod__(y) <==> x % y"""
+ """Return self%value."""
+
+ def __rmod__():
+ """Return value%self."""
def __ne__():
"""x.__ne__(y) <==> x!=y"""
@@ -1176,6 +1184,8 @@
doc=BytearrayDocstrings.__delitem__.__doc__),
__mod__ = interp2app(W_BytearrayObject.descr_mod,
doc=BytearrayDocstrings.__mod__.__doc__),
+ __rmod__ = interp2app(W_BytearrayObject.descr_rmod,
+ doc=BytearrayDocstrings.__rmod__.__doc__),
append = interp2app(W_BytearrayObject.descr_append,
doc=BytearrayDocstrings.append.__doc__),
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
@@ -583,6 +583,10 @@
assert bytearray(b'%04X') % 10 == b'000A'
assert bytearray(b'%c') % 48 == b'0'
assert bytearray(b'%c') % b'a' == b'a'
+ assert bytearray(b'%c') % bytearray(b'a') == b'a'
+
+ raises(TypeError, bytearray(b'a').__mod__, 5)
+ assert bytearray(b'a').__rmod__(5) == NotImplemented
"""
def test_format_b(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit