Skip to content

Commit e043c6e

Browse files
Implement keys() and items() for AttrDict
1 parent ff406e9 commit e043c6e

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

elasticsearch_dsl/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def __iter__(self):
187187
def to_dict(self):
188188
return self._d_
189189

190+
def keys(self):
191+
return self._d_.keys()
192+
193+
def items(self):
194+
return self._d_.items()
195+
190196

191197
class DslMeta(type):
192198
"""

tests/test_integration/_async/test_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async def test_update_object_field(async_write_client):
219219
)
220220
await w.save()
221221

222-
assert "updated" == await w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
222+
assert "updated" == await w.update(owner=[{"name": "Honza"}, User(name="Nick")])
223223
assert w.owner[0].name == "Honza"
224224
assert w.owner[1].name == "Nick"
225225

tests/test_integration/_sync/test_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def test_update_object_field(write_client):
219219
)
220220
w.save()
221221

222-
assert "updated" == w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
222+
assert "updated" == w.update(owner=[{"name": "Honza"}, User(name="Nick")])
223223
assert w.owner[0].name == "Honza"
224224
assert w.owner[1].name == "Nick"
225225

tests/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class MyAttrDict(utils.AttrDict):
4444
assert isinstance(l[:][0], MyAttrDict)
4545

4646

47+
def test_attrdict_keys_items():
48+
a = utils.AttrDict({"a": {"b": 42, "c": 47}, "d": "e"})
49+
assert list(a.keys()) == ["a", "d"]
50+
assert list(a.items()) == [("a", {"b": 42, "c": 47}), ("d", "e")]
51+
52+
4753
def test_merge():
4854
a = utils.AttrDict({"a": {"b": 42, "c": 47}})
4955
b = {"a": {"b": 123, "d": -12}, "e": [1, 2, 3]}

0 commit comments

Comments
 (0)