Skip to content

Commit c46b742

Browse files
committed
Rename method _to_dict to to_dict
1 parent b47c720 commit c46b742

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

zenmoney/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def diff(self, diff: Diff, debug=False) -> Diff:
2323
'''
2424
Accept the Diff object and returns Diff object
2525
'''
26-
response = self.__post(self.uri_diff, json=Diff._to_dict(diff))
26+
response = self.__post(self.uri_diff, json=Diff.to_dict(diff))
2727
if debug:
2828
self._plain_diff = response.json()
2929

@@ -35,7 +35,7 @@ def suggest(self, transaction: object) -> Transaction:
3535
returns the same data with suggestions
3636
'''
3737
response = self.__post(self.uri_suggest,
38-
json={'transaction': transaction._to_dict()})
38+
json={'transaction': transaction.to_dict()})
3939
return response.json()
4040

4141
def __post(self, uri: str, **kwargs):

zenmoney/zenobject.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ def to_dict(obj, classkey=None):
55
if isinstance(obj, dict):
66
data = {}
77
for (k, v) in obj.items():
8-
data[k] = ZenObject._to_dict(v, classkey)
8+
data[k] = to_dict(v, classkey)
99

1010
return data
1111
elif hasattr(obj, '__iter__') and not isinstance(obj, str):
12-
return [ZenObject._to_dict(v, classkey) for v in obj]
12+
return [to_dict(v, classkey) for v in obj]
1313
elif hasattr(obj, '__dict__'):
1414
data = dict([
15-
(key, ZenObject._to_dict(getattr(obj, key), classkey))
15+
(key, to_dict(getattr(obj, key), classkey))
16+
# __dir__ is used here to get dynamic properties
17+
# like Diff.currentClientTimestamp as well
1618
for key in obj.__dir__()
1719
if not key.startswith('_')
1820
and not callable(getattr(obj, key))
@@ -38,7 +40,7 @@ def __eq__(self, obj):
3840
def _type(self):
3941
return type(self).__name__
4042

41-
def _to_dict(self, classkey=None):
43+
def to_dict(self, classkey=None):
4244
return to_dict(self, classkey)
4345

4446

@@ -87,5 +89,5 @@ def _by_attr(self, attr, value):
8789
if value == attr_value:
8890
yield o
8991

90-
def _to_dict(self, classkey=None):
92+
def to_dict(self, classkey=None):
9193
return to_dict(self, classkey)

0 commit comments

Comments
 (0)