Skip to content

Commit

Permalink
Add AttrList.to_list() (#1584)
Browse files Browse the repository at this point in the history
* Add AttrList.to_list()

* simplify to_list() implementation

* code formatting

---------

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
(cherry picked from commit b059c0a)
  • Loading branch information
kujiy authored and github-actions[bot] committed Apr 29, 2024
1 parent e30129d commit ebacf80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions elasticsearch_dsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == [{}, {}]

0 comments on commit ebacf80

Please sign in to comment.