Skip to content

Implement keys() and items() for AttrDict #1784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions elasticsearch_dsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def __iter__(self):
def to_dict(self):
return self._d_

def keys(self):
return self._d_.keys()

def items(self):
return self._d_.items()


class DslMeta(type):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration/_async/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def test_update_object_field(async_write_client):
)
await w.save()

assert "updated" == await w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
assert "updated" == await w.update(owner=[{"name": "Honza"}, User(name="Nick")])
assert w.owner[0].name == "Honza"
assert w.owner[1].name == "Nick"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration/_sync/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_update_object_field(write_client):
)
w.save()

assert "updated" == w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
assert "updated" == w.update(owner=[{"name": "Honza"}, User(name="Nick")])
assert w.owner[0].name == "Honza"
assert w.owner[1].name == "Nick"

Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class MyAttrDict(utils.AttrDict):
assert isinstance(l[:][0], MyAttrDict)


def test_attrdict_keys_items():
a = utils.AttrDict({"a": {"b": 42, "c": 47}, "d": "e"})
assert list(a.keys()) == ["a", "d"]
assert list(a.items()) == [("a", {"b": 42, "c": 47}), ("d", "e")]


def test_merge():
a = utils.AttrDict({"a": {"b": 42, "c": 47}})
b = {"a": {"b": 123, "d": -12}, "e": [1, 2, 3]}
Expand Down
Loading