From ec49242dba9ae327968108877d7b12e768445b1d Mon Sep 17 00:00:00 2001 From: Colinxu2020 <63941938+colinxu2020@users.noreply.github.com> Date: Tue, 12 May 2026 22:47:02 +0800 Subject: [PATCH 1/4] Remove steal flag from bytes concatenation --- mypyc/primitives/bytes_ops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mypyc/primitives/bytes_ops.py b/mypyc/primitives/bytes_ops.py index 2db4879441025..96e8069f317ed 100644 --- a/mypyc/primitives/bytes_ops.py +++ b/mypyc/primitives/bytes_ops.py @@ -64,7 +64,6 @@ return_type=bytes_rprimitive, c_function_name="CPyBytes_Concat", error_kind=ERR_MAGIC, - steals=[True, False], ) # bytes * int From 9010e28b421e9b12d79ca0bbfaaeb5aa5428883d Mon Sep 17 00:00:00 2001 From: Colinxu2020 Date: Tue, 12 May 2026 23:30:46 +0800 Subject: [PATCH 2/4] Add Tests for Bytes Concat --- mypyc/test-data/irbuild-bytes.test | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index b149e0a96cdf6..740475aa7ba1e 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -299,3 +299,26 @@ def foo(b: bytes, ba: bytearray) -> None: [out] main:7: error: Argument 1 to "bytes_func" has incompatible type "bytearray"; expected "bytes" main:8: error: Argument 1 to "bytearray_func" has incompatible type "bytes"; expected "bytearray" + +[case testBytesConcatRefcount] +def f(a: bytes, b: bytes) -> bytes: + return b"1" + b +[out] +def f(a, b): + a, b, r0, r1 :: bytes +L0: + r0 = b'1' + r1 = CPyBytes_Concat(r0, b) + return r1 + +[case testChainedBytesConcatRefcount] +def f(a: bytes, b: bytes, c: bytes) -> bytes: + return b"1" + b + c +[out] +def f(a, b, c): + a, b, c, r0, r1, r2 :: bytes +L0: + r0 = b'1' + r1 = CPyBytes_Concat(r0, b) + r2 = CPyBytes_Concat(r1, c) + return r2 From 864a11bc2e28f125a3731e51b9d6a30bdb3b43d0 Mon Sep 17 00:00:00 2001 From: Colinxu2020 Date: Wed, 13 May 2026 08:08:47 +0800 Subject: [PATCH 3/4] fix tests --- mypyc/test-data/irbuild-bytes.test | 23 ----------------------- mypyc/test-data/refcount.test | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index 740475aa7ba1e..b149e0a96cdf6 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -299,26 +299,3 @@ def foo(b: bytes, ba: bytearray) -> None: [out] main:7: error: Argument 1 to "bytes_func" has incompatible type "bytearray"; expected "bytes" main:8: error: Argument 1 to "bytearray_func" has incompatible type "bytes"; expected "bytearray" - -[case testBytesConcatRefcount] -def f(a: bytes, b: bytes) -> bytes: - return b"1" + b -[out] -def f(a, b): - a, b, r0, r1 :: bytes -L0: - r0 = b'1' - r1 = CPyBytes_Concat(r0, b) - return r1 - -[case testChainedBytesConcatRefcount] -def f(a: bytes, b: bytes, c: bytes) -> bytes: - return b"1" + b + c -[out] -def f(a, b, c): - a, b, c, r0, r1, r2 :: bytes -L0: - r0 = b'1' - r1 = CPyBytes_Concat(r0, b) - r2 = CPyBytes_Concat(r1, c) - return r2 diff --git a/mypyc/test-data/refcount.test b/mypyc/test-data/refcount.test index 2f03a159dfacb..8f9382a6335fe 100644 --- a/mypyc/test-data/refcount.test +++ b/mypyc/test-data/refcount.test @@ -2125,3 +2125,32 @@ L3: r8 = box(None, 1) inc_ref r8 return r8 + +[case testBytesConcatRefcount] +def f(a: bytes, b: bytes) -> bytes: + return b"1" + a + b +[out] +def f(a, b): + a, b, r0, r1, r2 :: bytes +L0: + r0 = b'1' + r1 = CPyBytes_Concat(r0, a) + r2 = CPyBytes_Concat(r1, b) + dec_ref r1 + return r2 + +[case testChainedBytesConcatRefcount] +def f(a: bytes, b: bytes, c: bytes) -> bytes: + return b"1" + a + b + c +[out] +def f(a, b, c): + a, b, c, r0, r1, r2, r3 :: bytes +L0: + r0 = b'1' + r1 = CPyBytes_Concat(r0, a) + r2 = CPyBytes_Concat(r1, b) + dec_ref r1 + r3 = CPyBytes_Concat(r2, c) + dec_ref r2 + return r3 + From bcb04d03828f6e739ccd975cf0b322f12a47f470 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 00:10:27 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/test-data/refcount.test | 1 - 1 file changed, 1 deletion(-) diff --git a/mypyc/test-data/refcount.test b/mypyc/test-data/refcount.test index 8f9382a6335fe..918c84ee3b0ad 100644 --- a/mypyc/test-data/refcount.test +++ b/mypyc/test-data/refcount.test @@ -2153,4 +2153,3 @@ L0: r3 = CPyBytes_Concat(r2, c) dec_ref r2 return r3 -