Skip to content

Commit 847f763

Browse files
vrdmrgavin-aguiarpdthummar
authored
Adding new to_dict method for Document (#171)
* Adding new to_dict method for Document * nit; cls to self --------- Co-authored-by: gavin-aguiar <[email protected]> Co-authored-by: pdthummar <[email protected]>
1 parent 4e32a20 commit 847f763

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

azure/functions/_abc.py

+4
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ def __setitem__(self, key, value):
380380
def to_json(self) -> str:
381381
pass
382382

383+
@abc.abstractmethod
384+
def to_dict(self) -> dict:
385+
pass
386+
383387

384388
class DocumentList(abc.ABC):
385389
pass

azure/functions/_cosmosdb.py

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def to_json(self) -> str:
2727
"""Return the JSON representation of the document."""
2828
return json.dumps(dict(self))
2929

30+
def to_dict(self) -> dict:
31+
"""Return the document as a dict - directly using self would also work
32+
as Document is ``UserDict`` subclass and behave like dict"""
33+
return dict(self)
34+
3035
def __getitem__(self, key):
3136
return collections.UserDict.__getitem__(self, key)
3237

0 commit comments

Comments
 (0)