@@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None:
133133 return _result
134134 """
135135
136- def find (self , query : Mapping = None , limit : tuple = None ) -> List [Document | None ]:
136+ def find (self , query = None , limit = None ) -> List [Document ]:
137137 """
138138 Finds all ``Document`` of ``Collection``.
139139
@@ -145,17 +145,24 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
145145 :param query: Condition to search Document
146146 :return: List of Document
147147 """
148+
148149 # Default result
149150 _result = []
150151
151152 # Make sure the query implements the ``Mapping`` interface.
152- if not isinstance (query , Mapping | None ):
153- raise ValueError ('Document is not a Dictionary' )
153+ if query :
154+ if not isinstance (query , Mapping ):
155+ raise ValueError ('Document is not a Dictionary' )
156+
157+ # Make sure the query implements the ``Tuple`` interface.
158+ if limit :
159+ if not isinstance (limit , tuple ):
160+ raise ValueError ('Document is not a Tuple' )
154161
155162 # if limit, Check everything ok
156163 _limit_start = _limit_end = None
157164
158- if limit :
165+ if limit and type ( limit ) == type (( 1 , 3 )) :
159166 if len (limit ) == 2 :
160167
161168 _limit_start = limit [0 ]
@@ -175,15 +182,16 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
175182
176183 # check if lower limit is valid or not
177184 if _limit_start >= len (self ._collection ):
178- raise ValueError (f"Lower limit should be smaller than Collection length.\n It must be less than `{ len (self ._collection )} `. `{ _limit_start } ` is given." )
185+ raise ValueError (
186+ f"Lower limit should be smaller than Collection length.\n It must be less than `{ len (self ._collection )} `. `{ _limit_start } ` is given." )
179187 else :
180188 _result = self ._collection [_limit_start : _limit_end ]
181189 else :
182190 _result = self ._collection
183191
184192 return _result
185193
186- elif query is not None :
194+ elif query is not None and type ( query ) == type ({}) :
187195 if limit :
188196 for i in self ._collection :
189197 _doc = self ._find_document_by_query (query )
@@ -212,11 +220,14 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No
212220
213221 if _doc :
214222 _result += _doc
223+ else :
224+ _result = _result
225+
215226 self ._reset_cursor ()
216227
217228 return _result
218229
219- def delete (self , query : Mapping = None ) -> List [str ]:
230+ def delete (self , query = None ) -> List [str ]:
220231 """
221232 Delete single or multiple Document when meet the Conditions or ``query``.
222233
@@ -241,7 +252,7 @@ def delete(self, query: Mapping = None) -> List[str]:
241252
242253 return _doc_id
243254
244- def update (self , document : Mapping , query : Mapping = None ) -> List [str ]:
255+ def update (self , document : Mapping , query = None ) -> List [str ]:
245256 """
246257 Fetch all the Documents mathc the conditions and update them.
247258
@@ -277,8 +288,7 @@ def update(self, document: Mapping, query: Mapping = None) -> List[str]:
277288
278289 return _doc_id
279290
280-
281- def count (self , query : Mapping = None , limit : tuple = None ) -> int :
291+ def count (self , query = None , limit : tuple = None ) -> int :
282292 """
283293 Return amount of Document found.
284294
@@ -297,7 +307,7 @@ def _reset_cursor(self) -> None:
297307 """
298308 self ._cursor = 0
299309
300- def _find_document_by_query (self , query : Mapping ) -> List | None :
310+ def _find_document_by_query (self , query : Mapping ) -> List :
301311 """
302312 Finds a single ``Document`` of ``Collection``.
303313
@@ -309,7 +319,7 @@ def _find_document_by_query(self, query: Mapping) -> List | None:
309319 result = []
310320
311321 # Make sure the query implements the ``Mapping`` interface.
312- if not isinstance (query , Mapping | None ):
322+ if not isinstance (query , Mapping ):
313323 raise ValueError ('Document is not a Dictionary' )
314324
315325 # Get the length on Collection
@@ -341,7 +351,6 @@ def _find_document_by_query(self, query: Mapping) -> List | None:
341351 # If both values are same, then update ``_bag_of_query[i]`` as 1.
342352 _bag_of_query [i ] = 1
343353
344-
345354 else :
346355 continue
347356 else :
@@ -365,17 +374,17 @@ def _find_document_by_query(self, query: Mapping) -> List | None:
365374 return result
366375
367376 # ======================== #
368- def _doc_is_exists (self , doc_id : str | int ) -> bool :
377+ def _doc_is_exists (self , doc_id : str ) -> bool :
369378 # Iterate over all Documents of Collection
370379 for doc in self ._collection :
371380 if doc ["_id_" ] == doc_id :
372381 return True
373382
374383 return False
375384
376- def _find_document_by_id (self , doc_id ) -> Document | str :
385+ def _find_document_by_id (self , doc_id ) -> Document :
377386 for doc in self ._collection :
378387 if doc ["_id_" ] == doc_id :
379388 return doc
380389 else :
381- return "none"
390+ return None
0 commit comments