@@ -79,8 +79,8 @@ def test_concat() -> None:
7979 assert type(b1) == bytes
8080 assert type(b2) == bytes
8181 assert type(b3) == bytes
82- brr1: bytes = bytearray(3)
83- brr2: bytes = bytearray(range(5))
82+ brr1 = bytearray(3)
83+ brr2 = bytearray(range(5))
8484 b4 = b1 + brr1
8585 assert b4 == b'123\x00\x00\x00'
8686 assert type(brr1) == bytearray
@@ -94,9 +94,9 @@ def test_concat() -> None:
9494 b5 = brr2 + b2
9595 assert b5 == bytearray(b'\x00\x01\x02\x03\x04456')
9696 assert type(b5) == bytearray
97- b5 = b2 + brr2
98- assert b5 == b'456\x00\x01\x02\x03\x04'
99- assert type(b5 ) == bytes
97+ b6 = b2 + brr2
98+ assert b6 == b'456\x00\x01\x02\x03\x04'
99+ assert type(b6 ) == bytes
100100
101101def test_join() -> None:
102102 seq = (b'1', b'"', b'\xf0')
@@ -217,9 +217,9 @@ def test_startswith() -> None:
217217 assert test.startswith(bytearray(b'some'))
218218 assert not test.startswith(bytearray(b'other'))
219219
220- test = bytearray(b'some string')
221- assert test .startswith(b'some')
222- assert not test .startswith(b'other')
220+ test2 = bytearray(b'some string')
221+ assert test2 .startswith(b'some')
222+ assert not test2 .startswith(b'other')
223223
224224[case testBytesSlicing]
225225def test_bytes_slicing() -> None:
@@ -257,34 +257,38 @@ def test_bytes_slicing() -> None:
257257[case testBytearrayBasics]
258258from typing import Any
259259
260+ from testutil import assertRaises
261+
260262def test_basics() -> None:
261- brr1: bytes = bytearray(3)
263+ brr1 = bytearray(3)
262264 assert brr1 == bytearray(b'\x00\x00\x00')
263265 assert brr1 == b'\x00\x00\x00'
264266 l = [10, 20, 30, 40]
265- brr2: bytes = bytearray(l)
267+ brr2 = bytearray(l)
266268 assert brr2 == bytearray(b'\n\x14\x1e(')
267269 assert brr2 == b'\n\x14\x1e('
268- brr3: bytes = bytearray(range(5))
270+ brr3 = bytearray(range(5))
269271 assert brr3 == bytearray(b'\x00\x01\x02\x03\x04')
270272 assert brr3 == b'\x00\x01\x02\x03\x04'
271- brr4: bytes = bytearray('string', 'utf-8')
273+ brr4 = bytearray('string', 'utf-8')
272274 assert brr4 == bytearray(b'string')
273275 assert brr4 == b'string'
274276 assert len(brr1) == 3
275277 assert len(brr2) == 4
276278
277- def f(b: bytes) -> bool :
278- return True
279+ def f(b: bytes) -> str :
280+ return "xy"
279281
280282def test_bytearray_passed_into_bytes() -> None:
281- assert f(bytearray(3))
282283 brr1: Any = bytearray()
283- assert f(brr1)
284+ with assertRaises(TypeError, "bytes object expected; got bytearray"):
285+ f(brr1)
286+ with assertRaises(TypeError, "bytes object expected; got bytearray"):
287+ b: bytes = brr1
284288
285289[case testBytearraySlicing]
286290def test_bytearray_slicing() -> None:
287- b: bytes = bytearray(b'abcdefg')
291+ b = bytearray(b'abcdefg')
288292 zero = int()
289293 ten = 10 + zero
290294 two = 2 + zero
@@ -318,7 +322,7 @@ def test_bytearray_slicing() -> None:
318322from testutil import assertRaises
319323
320324def test_bytearray_indexing() -> None:
321- b: bytes = bytearray(b'\xae\x80\xfe\x15')
325+ b = bytearray(b'\xae\x80\xfe\x15')
322326 assert b[0] == 174
323327 assert b[1] == 128
324328 assert b[2] == 254
@@ -347,10 +351,6 @@ def test_bytes_join() -> None:
347351 assert b' '.join([b'a', b'b']) == b'a b'
348352 assert b' '.join([]) == b''
349353
350- x: bytes = bytearray(b' ')
351- assert x.join([b'a', b'b']) == b'a b'
352- assert type(x.join([b'a', b'b'])) == bytearray
353-
354354 y: bytes = bytes_subclass()
355355 assert y.join([]) == b'spook'
356356
0 commit comments