Skip to content

Commit e932081

Browse files
committed
refactor: rename functions
1 parent b0102a3 commit e932081

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/json_as_db/Database.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
)
1818

1919

20-
def from_maybe_list(value: Union[Any, List[Any]]) -> Tuple[type, List[Any]]:
20+
def _from_maybe_list(value: Union[Any, List[Any]]) -> Tuple[type, List[Any]]:
2121
return_type = type(value)
2222
if not isinstance(value, list):
2323
value = [value]
2424
return (return_type, value)
2525

2626

27-
def return_maybe(_type: type, _values: List[Any]) -> Union[Any, List[Any]]:
27+
def _return_maybe(_type: type, _values: List[Any]) -> Union[Any, List[Any]]:
2828
if _type is list:
2929
return _values
3030
else:
3131
return _values[0]
3232

3333

34-
def override_only_unset(__dict: dict, __target: dict):
34+
def _override_only_unset(__dict: dict, __target: dict):
3535
unset_fields = set(__target.keys()) - set(__dict.keys())
3636
new_target = dict()
3737
for field in unset_fields:
@@ -62,7 +62,7 @@ def __init__(self, *arg, **kwargs):
6262
'updated_at': now,
6363
self.__records__: dict(),
6464
}
65-
self.__dict__ = override_only_unset(self.__dict__, defaults)
65+
self.__dict__ = _override_only_unset(self.__dict__, defaults)
6666

6767
def __getitem__(self, key: str) -> Any:
6868
try:
@@ -110,9 +110,9 @@ def metadata(self) -> dict:
110110
return meta
111111

112112
def get(self, key: Union[str, List[str]], default=None) -> Union[Any, List[Any]]:
113-
_type, _keys = from_maybe_list(key)
113+
_type, _keys = _from_maybe_list(key)
114114
values = [self.records.get(k, default) for k in _keys]
115-
return return_maybe(_type, values)
115+
return _return_maybe(_type, values)
116116

117117
def update(self, mapping: Union[dict, tuple] = (), **kwargs) -> None:
118118
return self.records.update(mapping, **kwargs)
@@ -122,8 +122,8 @@ def modify(
122122
id: Union[str, List[str]],
123123
value: Union[Any, List[Any]]
124124
) -> None:
125-
type_id, ids = from_maybe_list(id)
126-
type_value, values = from_maybe_list(value)
125+
type_id, ids = _from_maybe_list(id)
126+
type_value, values = _from_maybe_list(value)
127127
if len(ids) != len(values):
128128
raise ValueError('Can not match ids and values. please check type and length of them')
129129
for index in range(len(ids)):
@@ -134,20 +134,20 @@ def modify(
134134
self.records.update(target)
135135

136136
def add(self, item: Union[Any, List[Any]]) -> Union[str, List[str]]:
137-
_type, _items = from_maybe_list(item)
137+
_type, _items = _from_maybe_list(item)
138138

139139
ids = []
140140
for i in _items:
141141
uid = shortuuid.uuid()
142142
self.records[uid] = i
143143
ids.append(uid)
144144

145-
return return_maybe(_type, ids)
145+
return _return_maybe(_type, ids)
146146

147147
def remove(self, key: Union[str, List[str]]) -> Union[str, List[str]]:
148-
_type, _keys = from_maybe_list(key)
148+
_type, _keys = _from_maybe_list(key)
149149
popped = [self.records.pop(key) for key in _keys]
150-
return return_maybe(_type, popped)
150+
return _return_maybe(_type, popped)
151151

152152
def all(self) -> List[Any]:
153153
return self.records.values()
@@ -163,10 +163,10 @@ def find(self, func: Callable[..., bool]) -> List[str]:
163163
return ids
164164

165165
def has(self, key: Union[str, List[str]]) -> Union[bool, List[bool]]:
166-
_type, _keys = from_maybe_list(key)
166+
_type, _keys = _from_maybe_list(key)
167167
key_set = set(self.records.keys())
168168
values = [k in key_set for k in _keys]
169-
return return_maybe(_type, values)
169+
return _return_maybe(_type, values)
170170

171171
def count(self) -> int:
172172
"""
@@ -213,8 +213,8 @@ async def save(
213213
keyword arguments for `json.dumps(**kwargs)`.
214214
Defaults to `(sort_keys=True)`.
215215
"""
216-
file_kwds = override_only_unset(file_kwds, _defaults_save_file_kwargs)
217-
json_kwds = override_only_unset(json_kwds, _defaults_save_json_kwargs)
216+
file_kwds = _override_only_unset(file_kwds, _defaults_save_file_kwargs)
217+
json_kwds = _override_only_unset(json_kwds, _defaults_save_json_kwargs)
218218

219219
async with aiofiles.open(self.filepath, **file_kwds) as f:
220220
dict_out = dict(self.__dict__)

0 commit comments

Comments
 (0)