Skip to content

Commit 24ab9c4

Browse files
Add contains method to BytesType (#126)
1 parent 75445f5 commit 24ab9c4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/celpy/celtypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ def __new__(
442442
def __repr__(self) -> str:
443443
return f"{self.__class__.__name__}({super().__repr__()})"
444444

445+
def contains(self, item: Value) -> BoolType:
446+
return BoolType(cast(BytesType, item) in self)
447+
445448

446449
class DoubleType(float):
447450
"""

tests/test_celtypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_bytes_type():
8181
assert repr(b_0) == "BytesType(b'bytes')"
8282
assert BytesType(None) == BytesType(b'')
8383
assert BytesType(MessageType({"value": BytesType(b'42')})) == BytesType(b'42')
84+
assert b_0.contains(b'byte')
8485

8586

8687
def test_double_type():

0 commit comments

Comments
 (0)