From 2e865b078536674065e1d8f7ca82198f977c01fe Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 13 Nov 2025 20:23:16 +0100 Subject: [PATCH] __contains__ for lists added with test --- src/pelfy/_main.py | 8 ++++++++ tests/test_example_elfs.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/pelfy/_main.py b/src/pelfy/_main.py index 808e5e3..f93beba 100644 --- a/src/pelfy/_main.py +++ b/src/pelfy/_main.py @@ -265,6 +265,14 @@ class elf_list(Generic[_T]): def __iter__(self) -> Iterator[_T]: return iter(self._data) + def __contains__(self, item: Union[str, int, _T]) -> bool: + if isinstance(item, str): + return any(getattr(el, 'name', '') == item for el in self._data) + elif isinstance(item, int): + return 0 <= item < len(self._data) + else: + return item in self._data + def _compact_table(self) -> tuple[list[str], list[list[Union[str, int]]], list[str]]: return [], [[]], [] diff --git a/tests/test_example_elfs.py b/tests/test_example_elfs.py index d39c592..67c8b03 100644 --- a/tests/test_example_elfs.py +++ b/tests/test_example_elfs.py @@ -38,6 +38,13 @@ def test_simple_c() -> None: for reloc in elf.get_relocations(): assert known_name(reloc.type), f"Relocation type {reloc.type} for {elf.architecture} in {path} is unknown." + assert 'imageWidth' in elf.objects or 'read_float_ret' in elf.objects, path + assert 'leet456456456n4ghn4hf56n4f' not in elf.objects + assert 0 in elf.objects + assert 1000 not in elf.objects + assert elf.objects[0] in elf.symbols + assert elf.objects[0] not in elf.functions + if __name__ == '__main__': test_simple_c()