[Python-checkins] cpython: Issue #26764: Fixed SystemError in bytes.__rmod__.
serhiy.storchaka
python-checkins at python.org
Fri Apr 15 07:14:41 EDT 2016
https://hg.python.org/cpython/rev/ebece99c0bb6
changeset: 100982:ebece99c0bb6
parent: 100980:570ada02d0f0
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri Apr 15 14:11:10 2016 +0300
summary:
Issue #26764: Fixed SystemError in bytes.__rmod__.
files:
Lib/test/test_bytes.py | 37 ++++++++---------------------
Objects/bytesobject.c | 10 +++----
2 files changed, 15 insertions(+), 32 deletions(-)
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -483,26 +483,33 @@
self.assertRaises(ValueError, b.rindex, w, 1, 3)
def test_mod(self):
- b = b'hello, %b!'
+ b = self.type2test(b'hello, %b!')
orig = b
b = b % b'world'
self.assertEqual(b, b'hello, world!')
self.assertEqual(orig, b'hello, %b!')
self.assertFalse(b is orig)
- b = b'%s / 100 = %d%%'
+ b = self.type2test(b'%s / 100 = %d%%')
a = b % (b'seventy-nine', 79)
self.assertEqual(a, b'seventy-nine / 100 = 79%')
+ self.assertIs(type(a), bytes)
def test_imod(self):
- b = b'hello, %b!'
+ b = self.type2test(b'hello, %b!')
orig = b
b %= b'world'
self.assertEqual(b, b'hello, world!')
self.assertEqual(orig, b'hello, %b!')
self.assertFalse(b is orig)
- b = b'%s / 100 = %d%%'
+ b = self.type2test(b'%s / 100 = %d%%')
b %= (b'seventy-nine', 79)
self.assertEqual(b, b'seventy-nine / 100 = 79%')
+ self.assertIs(type(b), bytes)
+
+ def test_rmod(self):
+ with self.assertRaises(TypeError):
+ object() % self.type2test(b'abc')
+ self.assertIs(self.type2test(b'abc').__rmod__('%r'), NotImplemented)
def test_replace(self):
b = self.type2test(b'mississippi')
@@ -1064,28 +1071,6 @@
b[8:] = b
self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
- def test_mod(self):
- b = bytearray(b'hello, %b!')
- orig = b
- b = b % b'world'
- self.assertEqual(b, b'hello, world!')
- self.assertEqual(orig, bytearray(b'hello, %b!'))
- self.assertFalse(b is orig)
- b = bytearray(b'%s / 100 = %d%%')
- a = b % (b'seventy-nine', 79)
- self.assertEqual(a, bytearray(b'seventy-nine / 100 = 79%'))
-
- def test_imod(self):
- b = bytearray(b'hello, %b!')
- orig = b
- b %= b'world'
- self.assertEqual(b, b'hello, world!')
- self.assertEqual(orig, bytearray(b'hello, %b!'))
- self.assertFalse(b is orig)
- b = bytearray(b'%s / 100 = %d%%')
- b %= (b'seventy-nine', 79)
- self.assertEqual(b, bytearray(b'seventy-nine / 100 = 79%'))
-
def test_iconcat(self):
b = bytearray(b"abc")
b1 = b
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3282,15 +3282,13 @@
};
static PyObject *
-bytes_mod(PyObject *self, PyObject *args)
+bytes_mod(PyObject *self, PyObject *arg)
{
- if (self == NULL || !PyBytes_Check(self)) {
- PyErr_BadInternalCall();
- return NULL;
+ if (!PyBytes_Check(self)) {
+ Py_RETURN_NOTIMPLEMENTED;
}
-
return _PyBytes_FormatEx(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
- args, 0);
+ arg, 0);
}
static PyNumberMethods bytes_as_number = {
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list