From 25d4b3348a7a5837df0e385c60326e478f7180d9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 01/23] [mypyc] feat: new primitives for `bytes.rjust` and `bytes.ljust` --- mypyc/lib-rt/bytes_ops.c | 49 ++++++++++++++++++++++ mypyc/primitives/bytes_ops.py | 18 ++++++++ mypyc/test-data/irbuild-bytes.test | 66 ++++++++++++++++++++++++++++++ mypyc/test-data/run-bytes.test | 38 +++++++++++++++++ 4 files changed, 171 insertions(+) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 6ff34b021a9a..6983ba18875f 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -4,6 +4,7 @@ #include #include "CPy.h" +#include // Returns -1 on error, 0 on inequality, 1 on equality. // @@ -162,3 +163,51 @@ CPyTagged CPyBytes_Ord(PyObject *obj) { PyErr_SetString(PyExc_TypeError, "ord() expects a character"); return CPY_INT_TAG; } + +PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { + if (!PyBytes_Check(self)) { + PyErr_SetString(PyExc_TypeError, "self must be bytes"); + return NULL; + } + if (!PyBytes_Check(fillbyte) || PyBytes_Size(fillbyte) != 1) { + PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); + return NULL; + } + Py_ssize_t len = PyBytes_Size(self); + if (width <= len) { + return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + } + char fill = PyBytes_AsString(fillbyte)[0]; + Py_ssize_t pad = width - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width); + if (!result) return NULL; + char *res_buf = PyBytes_AsString(result); + memset(res_buf, fill, pad); + memcpy(res_buf + pad, PyBytes_AsString(self), len); + return result; +} + +PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { + if (!PyBytes_Check(self)) { + PyErr_SetString(PyExc_TypeError, "self must be bytes"); + return NULL; + } + if (!PyBytes_Check(fillbyte) || PyBytes_Size(fillbyte) != 1) { + PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); + return NULL; + } + Py_ssize_t len = PyBytes_Size(self); + if (width <= len) { + return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + } + char fill = PyBytes_AsString(fillbyte)[0]; + Py_ssize_t pad = width - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width); + if (!result) return NULL; + char *res_buf = PyBytes_AsString(result); + memcpy(res_buf, PyBytes_AsString(self), len); + memset(res_buf + len, fill, pad); + return result; +} + +// ... existing code ... diff --git a/mypyc/primitives/bytes_ops.py b/mypyc/primitives/bytes_ops.py index c88e89d1a2ba..88155110fc2d 100644 --- a/mypyc/primitives/bytes_ops.py +++ b/mypyc/primitives/bytes_ops.py @@ -126,3 +126,21 @@ c_function_name="CPyBytes_Ord", error_kind=ERR_MAGIC, ) + +# bytes.rjust(width, fillbyte=b' ') +method_op( + name="rjust", + arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], + return_type=bytes_rprimitive, + c_function_name="CPyBytes_Rjust", + error_kind=ERR_MAGIC, +) + +# bytes.ljust(width, fillbyte=b' ') +method_op( + name="ljust", + arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], + return_type=bytes_rprimitive, + c_function_name="CPyBytes_Ljust", + error_kind=ERR_MAGIC, +) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index 8cfefe03ae22..670968b16378 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -217,3 +217,69 @@ L2: L3: keep_alive y return r2 + +[case testBytesRjustDefault] +def f(b: bytes) -> bytes: + return b.rjust(6) +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.rjust(6, b' ') + return r0 + +[case testBytesRjustCustom] +def f(b: bytes) -> bytes: + return b.rjust(8, b'0') +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.rjust(8, b'0') + return r0 + +[case testBytesLjustDefault] +def f(b: bytes) -> bytes: + return b.ljust(7) +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.ljust(7, b' ') + return r0 + +[case testBytesLjustCustom] +def f(b: bytes) -> bytes: + return b.ljust(10, b'_') +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.ljust(10, b'_') + return r0 + +[case testBytesRjustNoPad] +def f(b: bytes) -> bytes: + return b.rjust(2) +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.rjust(2, b' ') + return r0 + +[case testBytesLjustNoPad] +def f(b: bytes) -> bytes: + return b.ljust(1) +[out] +def f(b): + b :: bytes + r0 :: bytes +L0: + r0 = b.ljust(1, b' ') + return r0 diff --git a/mypyc/test-data/run-bytes.test b/mypyc/test-data/run-bytes.test index df5cb209b902..70e1dc8671fd 100644 --- a/mypyc/test-data/run-bytes.test +++ b/mypyc/test-data/run-bytes.test @@ -401,3 +401,41 @@ def test_optional_ne() -> None: assert ne_b_b_opt(b'x', b'y') assert ne_b_b_opt(b'y', b'x') assert ne_b_b_opt(b'x', None) + +[case testBytesRjustLjust] +def rjust_bytes(b: bytes, width: int, fill: bytes = b' ') -> bytes: + return b.rjust(width, fill) + +def ljust_bytes(b: bytes, width: int, fill: bytes = b' ') -> bytes: + return b.ljust(width, fill) + +def test_rjust_with_default_fill() -> None: + assert rjust_bytes(b'abc', 6) == b' abc' + assert rjust_bytes(b'abc', 3) == b'abc' + assert rjust_bytes(b'abc', 2) == b'abc' + assert rjust_bytes(b'', 4) == b' ' + +def test_rjust_with_custom_fill() -> None: + assert rjust_bytes(b'abc', 6, b'0') == b'000abc' + assert rjust_bytes(b'abc', 5, b'_') == b'__abc' + assert rjust_bytes(b'abc', 3, b'X') == b'abc' + +def test_ljust_with_default_fill() -> None: + assert ljust_bytes(b'abc', 6) == b'abc ' + assert ljust_bytes(b'abc', 3) == b'abc' + assert ljust_bytes(b'abc', 2) == b'abc' + assert ljust_bytes(b'', 4) == b' ' + +def test_ljust_with_custom_fill() -> None: + assert ljust_bytes(b'abc', 6, b'0') == b'abc000' + assert ljust_bytes(b'abc', 5, b'_') == b'abc__' + assert ljust_bytes(b'abc', 3, b'X') == b'abc' + +def test_edge_cases() -> None: + assert rjust_bytes(b'abc', 0) == b'abc' + assert ljust_bytes(b'abc', 0) == b'abc' + # fillbyte must be length 1 + with assertRaises(TypeError): + rjust_bytes(b'abc', 5, b'') + with assertRaises(TypeError): + ljust_bytes(b'abc', 5, b'12') From bd8ecc3e5333d74ada911262bbdb54db8d358775 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 02/23] fix: tests --- mypyc/test-data/fixtures/ir.py | 2 ++ mypyc/test-data/run-bytes.test | 2 ++ 2 files changed, 4 insertions(+) diff --git a/mypyc/test-data/fixtures/ir.py b/mypyc/test-data/fixtures/ir.py index a4b4f3ce2b1f..46c1c78eff35 100644 --- a/mypyc/test-data/fixtures/ir.py +++ b/mypyc/test-data/fixtures/ir.py @@ -176,6 +176,8 @@ def __getitem__(self, i: slice) -> bytes: ... def join(self, x: Iterable[object]) -> bytes: ... def decode(self, encoding: str=..., errors: str=...) -> str: ... def __iter__(self) -> Iterator[int]: ... + def ljust(self, width: int, fillchar: bytes) -> bytes: ... + def rjust(self, width: int, fillchar: bytes) -> bytes: ... class bytearray: @overload diff --git a/mypyc/test-data/run-bytes.test b/mypyc/test-data/run-bytes.test index 70e1dc8671fd..8a9323b768b5 100644 --- a/mypyc/test-data/run-bytes.test +++ b/mypyc/test-data/run-bytes.test @@ -403,6 +403,8 @@ def test_optional_ne() -> None: assert ne_b_b_opt(b'x', None) [case testBytesRjustLjust] +from testutil import assertRaises + def rjust_bytes(b: bytes, width: int, fill: bytes = b' ') -> bytes: return b.rjust(width, fill) From 8797b7fa542efbc3350a1793d36476ad587588a0 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 03/23] Update bytes_ops.c --- mypyc/lib-rt/bytes_ops.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 6983ba18875f..554b9a58b6e1 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -209,5 +209,3 @@ PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { memset(res_buf + len, fill, pad); return result; } - -// ... existing code ... From f43d260493ce2aaa5e3c0b496a0eac81c2916831 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 04/23] fix: tests --- mypyc/test-data/fixtures/ir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypyc/test-data/fixtures/ir.py b/mypyc/test-data/fixtures/ir.py index 46c1c78eff35..42af24f0751a 100644 --- a/mypyc/test-data/fixtures/ir.py +++ b/mypyc/test-data/fixtures/ir.py @@ -176,8 +176,8 @@ def __getitem__(self, i: slice) -> bytes: ... def join(self, x: Iterable[object]) -> bytes: ... def decode(self, encoding: str=..., errors: str=...) -> str: ... def __iter__(self) -> Iterator[int]: ... - def ljust(self, width: int, fillchar: bytes) -> bytes: ... - def rjust(self, width: int, fillchar: bytes) -> bytes: ... + def ljust(self, width: int, fillchar: bytes | bytearray = b" ") -> bytes: ... + def rjust(self, width: int, fillchar: bytes | bytearray = b" ") -> bytes: ... class bytearray: @overload From 792d6ecab5a00ca8816d17faff299df469d0d143 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 05/23] add headers --- mypyc/lib-rt/CPy.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h index 5dec7509ac7b..513d643dc486 100644 --- a/mypyc/lib-rt/CPy.h +++ b/mypyc/lib-rt/CPy.h @@ -779,6 +779,8 @@ CPyTagged CPyBytes_GetItem(PyObject *o, CPyTagged index); PyObject *CPyBytes_Concat(PyObject *a, PyObject *b); PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter); CPyTagged CPyBytes_Ord(PyObject *obj); +PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte); +PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte); int CPyBytes_Compare(PyObject *left, PyObject *right); From 740cf8d8b8338418088cc5a21526a362dac01e68 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 06/23] deatil asserts --- mypyc/test-data/run-bytes.test | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mypyc/test-data/run-bytes.test b/mypyc/test-data/run-bytes.test index 8a9323b768b5..17b1c407e21e 100644 --- a/mypyc/test-data/run-bytes.test +++ b/mypyc/test-data/run-bytes.test @@ -412,30 +412,30 @@ def ljust_bytes(b: bytes, width: int, fill: bytes = b' ') -> bytes: return b.ljust(width, fill) def test_rjust_with_default_fill() -> None: - assert rjust_bytes(b'abc', 6) == b' abc' - assert rjust_bytes(b'abc', 3) == b'abc' - assert rjust_bytes(b'abc', 2) == b'abc' - assert rjust_bytes(b'', 4) == b' ' + assert rjust_bytes(b'abc', 6) == b' abc', rjust_bytes(b'abc', 6) + assert rjust_bytes(b'abc', 3) == b'abc', rjust_bytes(b'abc', 3) + assert rjust_bytes(b'abc', 2) == b'abc', rjust_bytes(b'abc', 2) + assert rjust_bytes(b'', 4) == b' ', rjust_bytes(b'', 4) def test_rjust_with_custom_fill() -> None: - assert rjust_bytes(b'abc', 6, b'0') == b'000abc' - assert rjust_bytes(b'abc', 5, b'_') == b'__abc' - assert rjust_bytes(b'abc', 3, b'X') == b'abc' + assert rjust_bytes(b'abc', 6, b'0') == b'000abc', rjust_bytes(b'abc', 6, b'0') + assert rjust_bytes(b'abc', 5, b'_') == b'__abc', rjust_bytes(b'abc', 5, b'_') + assert rjust_bytes(b'abc', 3, b'X') == b'abc', rjust_bytes(b'abc', 3, b'X') def test_ljust_with_default_fill() -> None: - assert ljust_bytes(b'abc', 6) == b'abc ' - assert ljust_bytes(b'abc', 3) == b'abc' - assert ljust_bytes(b'abc', 2) == b'abc' - assert ljust_bytes(b'', 4) == b' ' + assert ljust_bytes(b'abc', 6) == b'abc ', ljust_bytes(b'abc', 6) + assert ljust_bytes(b'abc', 3) == b'abc', ljust_bytes(b'abc', 3) + assert ljust_bytes(b'abc', 2) == b'abc', ljust_bytes(b'abc', 2) + assert ljust_bytes(b'', 4) == b' ', ljust_bytes(b'', 4) def test_ljust_with_custom_fill() -> None: - assert ljust_bytes(b'abc', 6, b'0') == b'abc000' - assert ljust_bytes(b'abc', 5, b'_') == b'abc__' - assert ljust_bytes(b'abc', 3, b'X') == b'abc' + assert ljust_bytes(b'abc', 6, b'0') == b'abc000', ljust_bytes(b'abc', 6, b'0') + assert ljust_bytes(b'abc', 5, b'_') == b'abc__', ljust_bytes(b'abc', 5, b'_') + assert ljust_bytes(b'abc', 3, b'X') == b'abc', ljust_bytes(b'abc', 3, b'X') def test_edge_cases() -> None: - assert rjust_bytes(b'abc', 0) == b'abc' - assert ljust_bytes(b'abc', 0) == b'abc' + assert rjust_bytes(b'abc', 0) == b'abc', rjust_bytes(b'abc', 0) + assert ljust_bytes(b'abc', 0) == b'abc', ljust_bytes(b'abc', 0) # fillbyte must be length 1 with assertRaises(TypeError): rjust_bytes(b'abc', 5, b'') From 960262cef2b6967bb789eba492f5e9e0000eda50 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 07/23] fix ir --- mypyc/test-data/irbuild-bytes.test | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index 670968b16378..1e43c940b24e 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -234,11 +234,11 @@ def f(b: bytes) -> bytes: return b.rjust(8, b'0') [out] def f(b): - b :: bytes - r0 :: bytes + b, r0 :: bytes L0: - r0 = b.rjust(8, b'0') - return r0 + r0 = b'_' + r1 = CPyBytes_Rjust(b, 20, r0) + return r1 [case testBytesLjustDefault] def f(b: bytes) -> bytes: @@ -256,11 +256,11 @@ def f(b: bytes) -> bytes: return b.ljust(10, b'_') [out] def f(b): - b :: bytes - r0 :: bytes + b, r0 :: bytes L0: - r0 = b.ljust(10, b'_') - return r0 + r0 = b'_' + r1 = CPyBytes_Ljust(b, 20, r0) + return r1 [case testBytesRjustNoPad] def f(b: bytes) -> bytes: From fa1ab2ae025d8c2cf5974205d2864e917bd0923d Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 08/23] fix run tests --- mypyc/lib-rt/bytes_ops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 554b9a58b6e1..9de71777c622 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -173,6 +173,7 @@ PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } + width = width << 1 Py_ssize_t len = PyBytes_Size(self); if (width <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); @@ -196,6 +197,7 @@ PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } + width = width << 1; Py_ssize_t len = PyBytes_Size(self); if (width <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); From cc376f9f5f8c1e5d2c6db321f8bcefaec9b92648 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 09/23] Update bytes_ops.c --- mypyc/lib-rt/bytes_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 9de71777c622..d01fb164ecc9 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -173,7 +173,7 @@ PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } - width = width << 1 + width = width << 1; Py_ssize_t len = PyBytes_Size(self); if (width <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); From 20187365a21e825ad232e2eab9624aaa00384090 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 10/23] Update bytes_ops.py --- mypyc/primitives/bytes_ops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypyc/primitives/bytes_ops.py b/mypyc/primitives/bytes_ops.py index 88155110fc2d..0c3eb4ed371e 100644 --- a/mypyc/primitives/bytes_ops.py +++ b/mypyc/primitives/bytes_ops.py @@ -130,7 +130,7 @@ # bytes.rjust(width, fillbyte=b' ') method_op( name="rjust", - arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], + arg_types=[bytes_rprimitive, c_pyssize_t_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, c_function_name="CPyBytes_Rjust", error_kind=ERR_MAGIC, @@ -139,7 +139,7 @@ # bytes.ljust(width, fillbyte=b' ') method_op( name="ljust", - arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], + arg_types=[bytes_rprimitive, c_pyssize_t_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, c_function_name="CPyBytes_Ljust", error_kind=ERR_MAGIC, From ac5e372d7d5e526fbd48fab31b38b994d13130e3 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 11/23] Update bytes_ops.c --- mypyc/lib-rt/bytes_ops.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index d01fb164ecc9..554b9a58b6e1 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -173,7 +173,6 @@ PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } - width = width << 1; Py_ssize_t len = PyBytes_Size(self); if (width <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); @@ -197,7 +196,6 @@ PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } - width = width << 1; Py_ssize_t len = PyBytes_Size(self); if (width <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); From 43aa239a35bd714f44108f2be694d503d06176cf Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 12/23] fix pyssizet --- mypyc/lib-rt/bytes_ops.c | 18 ++++++++++-------- mypyc/primitives/bytes_ops.py | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 554b9a58b6e1..b2182ccd9116 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -164,7 +164,7 @@ CPyTagged CPyBytes_Ord(PyObject *obj) { return CPY_INT_TAG; } -PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { +PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); return NULL; @@ -173,13 +173,14 @@ PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width) Py_ssize_t len = PyBytes_Size(self); - if (width <= len) { + if (width_size_t <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); } char fill = PyBytes_AsString(fillbyte)[0]; - Py_ssize_t pad = width - len; - PyObject *result = PyBytes_FromStringAndSize(NULL, width); + Py_ssize_t pad = width_size_t - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); if (!result) return NULL; char *res_buf = PyBytes_AsString(result); memset(res_buf, fill, pad); @@ -187,7 +188,7 @@ PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { return result; } -PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { +PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); return NULL; @@ -196,13 +197,14 @@ PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width) Py_ssize_t len = PyBytes_Size(self); - if (width <= len) { + if (width_size_t <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); } char fill = PyBytes_AsString(fillbyte)[0]; - Py_ssize_t pad = width - len; - PyObject *result = PyBytes_FromStringAndSize(NULL, width); + Py_ssize_t pad = width_size_t - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); if (!result) return NULL; char *res_buf = PyBytes_AsString(result); memcpy(res_buf, PyBytes_AsString(self), len); diff --git a/mypyc/primitives/bytes_ops.py b/mypyc/primitives/bytes_ops.py index 0c3eb4ed371e..88155110fc2d 100644 --- a/mypyc/primitives/bytes_ops.py +++ b/mypyc/primitives/bytes_ops.py @@ -130,7 +130,7 @@ # bytes.rjust(width, fillbyte=b' ') method_op( name="rjust", - arg_types=[bytes_rprimitive, c_pyssize_t_rprimitive, bytes_rprimitive], + arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, c_function_name="CPyBytes_Rjust", error_kind=ERR_MAGIC, @@ -139,7 +139,7 @@ # bytes.ljust(width, fillbyte=b' ') method_op( name="ljust", - arg_types=[bytes_rprimitive, c_pyssize_t_rprimitive, bytes_rprimitive], + arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, c_function_name="CPyBytes_Ljust", error_kind=ERR_MAGIC, From d352c104c866415ca7210e63e56e6e5daffe0fa5 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 13/23] fix headers --- mypyc/lib-rt/CPy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h index 513d643dc486..eabef9e5847f 100644 --- a/mypyc/lib-rt/CPy.h +++ b/mypyc/lib-rt/CPy.h @@ -779,8 +779,8 @@ CPyTagged CPyBytes_GetItem(PyObject *o, CPyTagged index); PyObject *CPyBytes_Concat(PyObject *a, PyObject *b); PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter); CPyTagged CPyBytes_Ord(PyObject *obj); -PyObject *CPyBytes_Ljust(PyObject *self, Py_ssize_t width, PyObject *fillbyte); -PyObject *CPyBytes_Rjust(PyObject *self, Py_ssize_t width, PyObject *fillbyte); +PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte); +PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte); int CPyBytes_Compare(PyObject *left, PyObject *right); From 009178a0d3d0d66d689f15ada4f058f586d619ee Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 14/23] fix: ; --- mypyc/lib-rt/bytes_ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index b2182ccd9116..b2dacd596395 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -173,7 +173,7 @@ PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } - Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width) + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); @@ -197,7 +197,7 @@ PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte) { PyErr_SetString(PyExc_TypeError, "fillbyte must be a single byte"); return NULL; } - Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width) + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); From 3e347b13b6f40c6b794592bcf7c73f48ca009d3f Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 15/23] fix ir --- mypyc/test-data/irbuild-bytes.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index 1e43c940b24e..c7d7d0466feb 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -234,10 +234,10 @@ def f(b: bytes) -> bytes: return b.rjust(8, b'0') [out] def f(b): - b, r0 :: bytes + b, r0, r1 :: bytes L0: - r0 = b'_' - r1 = CPyBytes_Rjust(b, 20, r0) + r0 = b'0' + r1 = CPyBytes_Rjust(b, 16, r0) return r1 [case testBytesLjustDefault] @@ -256,7 +256,7 @@ def f(b: bytes) -> bytes: return b.ljust(10, b'_') [out] def f(b): - b, r0 :: bytes + b, r0, r1 :: bytes L0: r0 = b'_' r1 = CPyBytes_Ljust(b, 20, r0) From f0bdaf4b971ed453b97a1ce0cb8e354cc8e7857b Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 16/23] drop dupe tests --- mypyc/test-data/irbuild-bytes.test | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index c7d7d0466feb..fbcb1b7368bf 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -261,25 +261,3 @@ L0: r0 = b'_' r1 = CPyBytes_Ljust(b, 20, r0) return r1 - -[case testBytesRjustNoPad] -def f(b: bytes) -> bytes: - return b.rjust(2) -[out] -def f(b): - b :: bytes - r0 :: bytes -L0: - r0 = b.rjust(2, b' ') - return r0 - -[case testBytesLjustNoPad] -def f(b: bytes) -> bytes: - return b.ljust(1) -[out] -def f(b): - b :: bytes - r0 :: bytes -L0: - r0 = b.ljust(1, b' ') - return r0 From 50cbf7c488c4d090ee1d3ad096becf0167151df1 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 17/23] Update bytes_ops.c --- mypyc/lib-rt/bytes_ops.c | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index b2dacd596395..652a859d057d 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -164,6 +164,31 @@ CPyTagged CPyBytes_Ord(PyObject *obj) { return CPY_INT_TAG; } + +PyObject *CPyBytes_RjustDefaultFill(PyObject *self, CPyTagged width) { + if (!PyBytes_Check(self)) { + PyErr_SetString(PyExc_TypeError, "self must be bytes"); + return NULL; + } + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); + Py_ssize_t len = PyBytes_Size(self); + if (width_size_t <= len) { + return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + } + // should this be a constant? + PyObject *fillbyte = PyBytes_FromStringAndSize(" ", 1); + // can we optimize out the above line and the below line? + char fill = PyBytes_AsString(fillbyte)[0]; + Py_ssize_t pad = width_size_t - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); + if (!result) return NULL; + char *res_buf = PyBytes_AsString(result); + memset(res_buf, fill, pad); + memcpy(res_buf + pad, PyBytes_AsString(self), len); + return result; +} + + PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); @@ -188,6 +213,31 @@ PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte) { return result; } + +PyObject *CPyBytes_LjustDefaultFill(PyObject *self, CPyTagged width) { + if (!PyBytes_Check(self)) { + PyErr_SetString(PyExc_TypeError, "self must be bytes"); + return NULL; + } + Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); + Py_ssize_t len = PyBytes_Size(self); + if (width_size_t <= len) { + return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + } + // should this be a constant? + PyObject *fillbyte = PyBytes_FromStringAndSize(" ", 1); + // can we optimize out the above line and the below line? + char fill = PyBytes_AsString(fillbyte)[0]; + Py_ssize_t pad = width_size_t - len; + PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); + if (!result) return NULL; + char *res_buf = PyBytes_AsString(result); + memcpy(res_buf, PyBytes_AsString(self), len); + memset(res_buf + len, fill, pad); + return result; +} + + PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); From 73de0bf47d4e5efb029db0a2d1c50f198d730d2b Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 18/23] Update CPy.h --- mypyc/lib-rt/CPy.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h index eabef9e5847f..a9d01ae3bf35 100644 --- a/mypyc/lib-rt/CPy.h +++ b/mypyc/lib-rt/CPy.h @@ -779,8 +779,10 @@ CPyTagged CPyBytes_GetItem(PyObject *o, CPyTagged index); PyObject *CPyBytes_Concat(PyObject *a, PyObject *b); PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter); CPyTagged CPyBytes_Ord(PyObject *obj); -PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte); -PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte); +PyObject *CPyBytes_LjustDefaultFill(PyObject *self, CPyTagged width); +PyObject *CPyBytes_RjustDefaultFill(PyObject *self, CPyTagged width); +PyObject *CPyBytes_LjustCustomFill(PyObject *self, CPyTagged width, PyObject *fillbyte); +PyObject *CPyBytes_RjustCustomFill(PyObject *self, CPyTagged width, PyObject *fillbyte); int CPyBytes_Compare(PyObject *left, PyObject *right); From d1e741a351d6eb2d13563c53458e83cd96d15f57 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 19/23] Update bytes_ops.py --- mypyc/primitives/bytes_ops.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/mypyc/primitives/bytes_ops.py b/mypyc/primitives/bytes_ops.py index 88155110fc2d..b4fe692fb4cd 100644 --- a/mypyc/primitives/bytes_ops.py +++ b/mypyc/primitives/bytes_ops.py @@ -127,20 +127,38 @@ error_kind=ERR_MAGIC, ) -# bytes.rjust(width, fillbyte=b' ') +# bytes.rjust(width) +method_op( + name="rjust", + arg_types=[bytes_rprimitive, int_rprimitive], + return_type=bytes_rprimitive, + c_function_name="CPyBytes_RjustDefaultFill", + error_kind=ERR_MAGIC, +) + +# bytes.rjust(width, fillbyte) method_op( name="rjust", arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, - c_function_name="CPyBytes_Rjust", + c_function_name="CPyBytes_RjustCustomFill", + error_kind=ERR_MAGIC, +) + +# bytes.ljust(width) +method_op( + name="ljust", + arg_types=[bytes_rprimitive, int_rprimitive], + return_type=bytes_rprimitive, + c_function_name="CPyBytes_LjustDefaultFill", error_kind=ERR_MAGIC, ) -# bytes.ljust(width, fillbyte=b' ') +# bytes.ljust(width, fillbyte) method_op( name="ljust", arg_types=[bytes_rprimitive, int_rprimitive, bytes_rprimitive], return_type=bytes_rprimitive, - c_function_name="CPyBytes_Ljust", + c_function_name="CPyBytes_LjustCustomFill", error_kind=ERR_MAGIC, ) From e6184ae53a3b2d079561d934ebee3662f3e97410 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 20/23] Update bytes_ops.c --- mypyc/lib-rt/bytes_ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index 652a859d057d..f6414041f0af 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -189,7 +189,7 @@ PyObject *CPyBytes_RjustDefaultFill(PyObject *self, CPyTagged width) { } -PyObject *CPyBytes_Rjust(PyObject *self, CPyTagged width, PyObject *fillbyte) { +PyObject *CPyBytes_RjustCustomFill(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); return NULL; @@ -238,7 +238,7 @@ PyObject *CPyBytes_LjustDefaultFill(PyObject *self, CPyTagged width) { } -PyObject *CPyBytes_Ljust(PyObject *self, CPyTagged width, PyObject *fillbyte) { +PyObject *CPyBytes_LjustCustomFill(PyObject *self, CPyTagged width, PyObject *fillbyte) { if (!PyBytes_Check(self)) { PyErr_SetString(PyExc_TypeError, "self must be bytes"); return NULL; From 63a6a50ec7c8ad168525c2ea75e3db66891123f7 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 21/23] Update irbuild-bytes.test --- mypyc/test-data/irbuild-bytes.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index fbcb1b7368bf..5bce6559e6c5 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -226,7 +226,7 @@ def f(b): b :: bytes r0 :: bytes L0: - r0 = b.rjust(6, b' ') + r0 = CPyBytes_RjustDefaultFill(b, 12) return r0 [case testBytesRjustCustom] @@ -237,7 +237,7 @@ def f(b): b, r0, r1 :: bytes L0: r0 = b'0' - r1 = CPyBytes_Rjust(b, 16, r0) + r1 = CPyBytes_RjustCustomFill(b, 16, r0) return r1 [case testBytesLjustDefault] @@ -248,7 +248,7 @@ def f(b): b :: bytes r0 :: bytes L0: - r0 = b.ljust(7, b' ') + r0 = CPyBytes_LjustDefaultFill(b, 14) return r0 [case testBytesLjustCustom] @@ -259,5 +259,5 @@ def f(b): b, r0, r1 :: bytes L0: r0 = b'_' - r1 = CPyBytes_Ljust(b, 20, r0) + r1 = CPyBytes_LjustCustomFill(b, 20, r0) return r1 From 702aaf2ff9a70528bb8fe6d401ac05ccd2445ad8 Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 22/23] optimize c funcs --- mypyc/lib-rt/bytes_ops.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/mypyc/lib-rt/bytes_ops.c b/mypyc/lib-rt/bytes_ops.c index f6414041f0af..7d1dd363203b 100644 --- a/mypyc/lib-rt/bytes_ops.c +++ b/mypyc/lib-rt/bytes_ops.c @@ -173,17 +173,14 @@ PyObject *CPyBytes_RjustDefaultFill(PyObject *self, CPyTagged width) { Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { - return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + Py_INCREF(self); + return self; } - // should this be a constant? - PyObject *fillbyte = PyBytes_FromStringAndSize(" ", 1); - // can we optimize out the above line and the below line? - char fill = PyBytes_AsString(fillbyte)[0]; Py_ssize_t pad = width_size_t - len; PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); if (!result) return NULL; char *res_buf = PyBytes_AsString(result); - memset(res_buf, fill, pad); + memset(res_buf, ' ', pad); memcpy(res_buf + pad, PyBytes_AsString(self), len); return result; } @@ -201,7 +198,8 @@ PyObject *CPyBytes_RjustCustomFill(PyObject *self, CPyTagged width, PyObject *fi Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { - return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + Py_INCREF(self); + return self; } char fill = PyBytes_AsString(fillbyte)[0]; Py_ssize_t pad = width_size_t - len; @@ -222,18 +220,15 @@ PyObject *CPyBytes_LjustDefaultFill(PyObject *self, CPyTagged width) { Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { - return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + Py_INCREF(self); + return self; } - // should this be a constant? - PyObject *fillbyte = PyBytes_FromStringAndSize(" ", 1); - // can we optimize out the above line and the below line? - char fill = PyBytes_AsString(fillbyte)[0]; Py_ssize_t pad = width_size_t - len; PyObject *result = PyBytes_FromStringAndSize(NULL, width_size_t); if (!result) return NULL; char *res_buf = PyBytes_AsString(result); memcpy(res_buf, PyBytes_AsString(self), len); - memset(res_buf + len, fill, pad); + memset(res_buf + len, ' ', pad); return result; } @@ -250,7 +245,8 @@ PyObject *CPyBytes_LjustCustomFill(PyObject *self, CPyTagged width, PyObject *fi Py_ssize_t width_size_t = CPyTagged_AsSsize_t(width); Py_ssize_t len = PyBytes_Size(self); if (width_size_t <= len) { - return PyBytes_FromStringAndSize(PyBytes_AsString(self), len); + Py_INCREF(self); + return self; } char fill = PyBytes_AsString(fillbyte)[0]; Py_ssize_t pad = width_size_t - len; From a7fc8ef88d1d0f4640931eb2e0b7c7238cba748a Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 26 Aug 2025 19:37:46 +0000 Subject: [PATCH 23/23] fix ir --- mypyc/test-data/irbuild-bytes.test | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/irbuild-bytes.test b/mypyc/test-data/irbuild-bytes.test index 5bce6559e6c5..1d6c002ab71e 100644 --- a/mypyc/test-data/irbuild-bytes.test +++ b/mypyc/test-data/irbuild-bytes.test @@ -223,8 +223,7 @@ def f(b: bytes) -> bytes: return b.rjust(6) [out] def f(b): - b :: bytes - r0 :: bytes + b, r0 :: bytes L0: r0 = CPyBytes_RjustDefaultFill(b, 12) return r0 @@ -245,8 +244,7 @@ def f(b: bytes) -> bytes: return b.ljust(7) [out] def f(b): - b :: bytes - r0 :: bytes + b, r0 :: bytes L0: r0 = CPyBytes_LjustDefaultFill(b, 14) return r0