Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into default-strict-bytes
  • Loading branch information
JelleZijlstra authored Feb 2, 2026
commit 6cbc7acd2b2a654c908c3b88c89aea05db18af3c
2 changes: 1 addition & 1 deletion mypyc/test-data/fixtures/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __setitem__(self, i: int, o: int) -> None: ...
@overload
def __getitem__(self, i: int) -> int: ...
@overload
def __getitem__(self, i: slice) -> bytes: ...
def __getitem__(self, i: slice) -> bytearray: ...
def decode(self, x: str = ..., y: str = ...) -> str: ...
def join(self, x: Iterable[object]) -> bytes: ...
def startswith(self, t: bytes) -> bool: ...
Expand Down
32 changes: 18 additions & 14 deletions mypyc/test-data/run-bytes.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def test_concat() -> None:
assert type(b1) == bytes
assert type(b2) == bytes
assert type(b3) == bytes
brr1: bytes | bytearray = bytearray(3)
brr2: bytes | bytearray = bytearray(range(5))
brr1 = bytearray(3)
brr2 = bytearray(range(5))
b4 = b1 + brr1
assert b4 == b'123\x00\x00\x00'
assert type(brr1) == bytearray
Expand Down Expand Up @@ -281,24 +281,32 @@ from typing import Any
from testutil import assertRaises

def test_basics() -> None:
brr1: bytes | bytearray = bytearray(3)
brr0 = bytearray()
assert brr0 == bytearray(b'')
assert brr0 == b''
assert len(brr0) == 0
brr1 = bytearray(3)
assert brr1 == bytearray(b'\x00\x00\x00')
assert brr1 == b'\x00\x00\x00'
l = [10, 20, 30, 40]
brr2: bytes | bytearray = bytearray(l)
brr2 = bytearray(l)
assert brr2 == bytearray(b'\n\x14\x1e(')
assert brr2 == b'\n\x14\x1e('
brr3: bytes | bytearray = bytearray(range(5))
brr3 = bytearray(range(5))
assert brr3 == bytearray(b'\x00\x01\x02\x03\x04')
assert brr3 == b'\x00\x01\x02\x03\x04'
brr4: bytes | bytearray = bytearray('string', 'utf-8')
brr4 = bytearray('string', 'utf-8')
assert brr4 == bytearray(b'string')
assert brr4 == b'string'
assert len(brr1) == 3
assert len(brr2) == 4

def f(b: bytes | bytearray) -> bool:
return True
def test_bytearray_type_object() -> None:
b = bytearray()
assert type(b) is bytearray

def fb(b: bytes | bytearray) -> str:
return "xy"

def test_bytearray_passed_into_bytes() -> None:
brr1: Any = bytearray()
Expand All @@ -319,7 +327,7 @@ def test_bytes_passed_into_bytearray() -> None:

[case testBytearraySlicing]
def test_bytearray_slicing() -> None:
b: bytes | bytearray = bytearray(b'abcdefg')
b = bytearray(b'abcdefg')
zero = int()
ten = 10 + zero
two = 2 + zero
Expand Down Expand Up @@ -353,7 +361,7 @@ def test_bytearray_slicing() -> None:
from testutil import assertRaises

def test_bytearray_indexing() -> None:
b: bytes | bytearray = bytearray(b'\xae\x80\xfe\x15')
b = bytearray(b'\xae\x80\xfe\x15')
assert b[0] == 174
assert b[1] == 128
assert b[2] == 254
Expand Down Expand Up @@ -382,10 +390,6 @@ def test_bytes_join() -> None:
assert b' '.join([b'a', b'b']) == b'a b'
assert b' '.join([]) == b''

x: bytes | bytearray = bytearray(b' ')
assert x.join([b'a', b'b']) == b'a b'
assert type(x.join([b'a', b'b'])) == bytearray

y: bytes = bytes_subclass()
assert y.join([]) == b'spook'

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.