mirror of https://github.com/python/cpython
Issue #26766: Fix _PyBytesWriter_Finish()
Return a bytearray object when bytearray is requested and when the small buffer is used. Fix also test_bytes: bytearray%args must return a bytearray type.
This commit is contained in:
parent
12bb6f4c7d
commit
e914d41312
|
@ -492,7 +492,7 @@ class BaseBytesTest:
|
|||
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)
|
||||
self.assertIs(type(a), self.type2test)
|
||||
|
||||
def test_imod(self):
|
||||
b = self.type2test(b'hello, %b!')
|
||||
|
@ -504,7 +504,7 @@ class BaseBytesTest:
|
|||
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)
|
||||
self.assertIs(type(b), self.type2test)
|
||||
|
||||
def test_rmod(self):
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
|
@ -4150,8 +4150,13 @@ _PyBytesWriter_Finish(_PyBytesWriter *writer, void *str)
|
|||
result = PyBytes_FromStringAndSize(NULL, 0);
|
||||
}
|
||||
else if (writer->use_small_buffer) {
|
||||
if (writer->use_bytearray) {
|
||||
result = PyByteArray_FromStringAndSize(writer->small_buffer, size);
|
||||
}
|
||||
else {
|
||||
result = PyBytes_FromStringAndSize(writer->small_buffer, size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = writer->buffer;
|
||||
writer->buffer = NULL;
|
||||
|
|
Loading…
Reference in New Issue