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.
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 966e287..a10ad5e 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -492,7 +492,7 @@
         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 @@
         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):