From 790b1a7f2a522308b213cdec38859725773289c3 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Fri, 25 Jul 2025 11:01:31 -0400 Subject: [PATCH 1/3] Add contains method to BytesType --- src/celpy/celtypes.py | 3 +++ tests/test_celtypes.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/celpy/celtypes.py b/src/celpy/celtypes.py index 8f6bf8f..339ca0d 100644 --- a/src/celpy/celtypes.py +++ b/src/celpy/celtypes.py @@ -442,6 +442,9 @@ def __new__( def __repr__(self) -> str: return f"{self.__class__.__name__}({super().__repr__()})" + def contains(self, item: Value) -> BoolType: + return BoolType(cast(StringType, item) in self) + class DoubleType(float): """ diff --git a/tests/test_celtypes.py b/tests/test_celtypes.py index f8cdd68..4afc4fe 100644 --- a/tests/test_celtypes.py +++ b/tests/test_celtypes.py @@ -81,6 +81,7 @@ def test_bytes_type(): assert repr(b_0) == "BytesType(b'bytes')" assert BytesType(None) == BytesType(b'') assert BytesType(MessageType({"value": BytesType(b'42')})) == BytesType(b'42') + assert b_0.contains("byte") def test_double_type(): From a4a87c432c9776f18a283d0c5017928f38ccbef9 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Tue, 2 Sep 2025 15:30:13 -0400 Subject: [PATCH 2/3] Fix cast and test --- src/celpy/celtypes.py | 2 +- tests/test_celtypes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/celpy/celtypes.py b/src/celpy/celtypes.py index 339ca0d..71115e3 100644 --- a/src/celpy/celtypes.py +++ b/src/celpy/celtypes.py @@ -443,7 +443,7 @@ def __repr__(self) -> str: return f"{self.__class__.__name__}({super().__repr__()})" def contains(self, item: Value) -> BoolType: - return BoolType(cast(StringType, item) in self) + return BoolType(cast(BytesType, item) in self) class DoubleType(float): diff --git a/tests/test_celtypes.py b/tests/test_celtypes.py index 4afc4fe..631e756 100644 --- a/tests/test_celtypes.py +++ b/tests/test_celtypes.py @@ -81,7 +81,7 @@ def test_bytes_type(): assert repr(b_0) == "BytesType(b'bytes')" assert BytesType(None) == BytesType(b'') assert BytesType(MessageType({"value": BytesType(b'42')})) == BytesType(b'42') - assert b_0.contains("byte") + assert b_0.contains(b"byte") def test_double_type(): From c66378cfb75502bf9245160531dd8d55c6d16a48 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Tue, 2 Sep 2025 15:35:14 -0400 Subject: [PATCH 3/3] Use single quotes --- tests/test_celtypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_celtypes.py b/tests/test_celtypes.py index 631e756..c0067f1 100644 --- a/tests/test_celtypes.py +++ b/tests/test_celtypes.py @@ -81,7 +81,7 @@ def test_bytes_type(): assert repr(b_0) == "BytesType(b'bytes')" assert BytesType(None) == BytesType(b'') assert BytesType(MessageType({"value": BytesType(b'42')})) == BytesType(b'42') - assert b_0.contains(b"byte") + assert b_0.contains(b'byte') def test_double_type():