From e0554c5e740cdd9c9d29a1ca4e689d1630fe0ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 10 Jan 2025 09:30:19 +0100 Subject: [PATCH] MAINT: rename the filter function of Container --- src/doc/tutorials/complex_data_models.rst | 2 +- src/linkahead/common/models.py | 10 +++++----- unittests/test_container.py | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/doc/tutorials/complex_data_models.rst b/src/doc/tutorials/complex_data_models.rst index d418298..52757c3 100644 --- a/src/doc/tutorials/complex_data_models.rst +++ b/src/doc/tutorials/complex_data_models.rst @@ -140,5 +140,5 @@ A short example: p1 = db.Property(id=101, name="Property 1") p2 = db.Property(name="Property 2") c = db.Container().extend([p1,p2]) - c.filter(name="Property 1") + c.filter_by_identity(name="Property 1") # Result: [p1] diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 0fc669c..c83354f 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -3736,21 +3736,21 @@ class Container(list): return sync_dict - def filter(self, entity: Optional[Entity] = None, - pid: Union[None, str, int] = None, + def filter_by_identity(self, entity: Optional[Entity] = None, + entity_id: Union[None, str, int] = None, name: Optional[str] = None, conjunction: bool = False) -> list: """ Return all Entities from this Container that match the selection criteria. - Please refer to the documentation of _filter_entity_list for a detailed + Please refer to the documentation of _filter_entity_list_by_identity for a detailed description of behaviour. Params ------ entity : Entity Entity to match name and ID with - pid : str, int + entity_id : str, int Parent ID to match name : str Parent name to match @@ -3764,7 +3764,7 @@ class Container(list): matches : list List containing all matching Entities """ - return _filter_entity_list(self, pid=pid, name=name, entity=entity, + return _filter_entity_list_by_identity(self, pid=entity_id, name=name, entity=entity, conjunction=conjunction) @staticmethod def _find_dependencies_in_container(container: Container): diff --git a/unittests/test_container.py b/unittests/test_container.py index 4ef8591..70498fd 100644 --- a/unittests/test_container.py +++ b/unittests/test_container.py @@ -201,10 +201,11 @@ def test_container_slicing(): cont[[0, 2, 3]] def test_container_filter(): - # this is a very rudimentary test since filter is based on _filter_entity_list which is tested + # this is a very rudimentary test since filter_by_identity is based on + # _filter_entity_list_by_identity which is tested # separately cont = db.Container() cont.extend([db.Record(name=f"TestRec{ii+1}") for ii in range(5)]) - recs = cont.filter(name="TestRec2") + recs = cont.filter_by_identity(name="TestRec2") assert len(recs)==1 recs[0].name =="TestRec2" -- GitLab