From b85a2c457329a90e8e66b8865bf6ee00541aee9a Mon Sep 17 00:00:00 2001 From: Kujiy Date: Thu, 25 Apr 2024 01:05:00 +0900 Subject: [PATCH] Add AttrList.to_list() (#1584) * Add AttrList.to_list() * simplify to_list() implementation * code formatting --------- Co-authored-by: Miguel Grinberg (cherry picked from commit b059c0ae7c015ca59354efe1a474255d0db725fe) --- elasticsearch_dsl/utils.py | 3 +++ tests/test_utils.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/elasticsearch_dsl/utils.py b/elasticsearch_dsl/utils.py index 3b231d256..1a8e89732 100644 --- a/elasticsearch_dsl/utils.py +++ b/elasticsearch_dsl/utils.py @@ -101,6 +101,9 @@ def __getstate__(self): def __setstate__(self, state): self._l_, self._obj_wrapper = state + def to_list(self): + return self._l_ + class AttrDict: """ diff --git a/tests/test_utils.py b/tests/test_utils.py index 73931d433..615b4c248 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -100,3 +100,9 @@ def test_recursive_to_dict(): assert utils.recursive_to_dict({"k": [1, (1.0, {"v": Q("match", key="val")})]}) == { "k": [1, (1.0, {"v": {"match": {"key": "val"}}})] } + + +def test_attrlist_to_list(): + l = utils.AttrList([{}, {}]).to_list() + assert isinstance(l, list) + assert l == [{}, {}]