122122# can describe both sync and async, where R itself is a coroutine
123123AnyDocMethod : TypeAlias = Callable [Concatenate [DocType , P ], R ]
124124# describes only async
125- AsyncDocMethod : TypeAlias = Callable [Concatenate [DocType , P ], Coroutine [Any , Any , R ]]
125+ AsyncDocMethod : TypeAlias = Callable [
126+ Concatenate [DocType , P ], Coroutine [Any , Any , R ]
127+ ]
126128DocumentProjectionType = TypeVar ("DocumentProjectionType" , bound = BaseModel )
127129
128130
@@ -225,7 +227,9 @@ def _fill_back_refs(cls, values):
225227 and field_name not in values
226228 ):
227229 values [field_name ] = [
228- BackLink [link_info .document_class ](link_info .document_class )
230+ BackLink [link_info .document_class ](
231+ link_info .document_class
232+ )
229233 ]
230234 return values
231235
@@ -306,7 +310,9 @@ async def sync(self, merge_strategy: MergeStrategy = MergeStrategy.remote):
306310 new_state = document .get_saved_state ()
307311 if new_state is None :
308312 raise DocumentWasNotSaved
309- changes_to_apply = self ._collect_updates (new_state , original_changes )
313+ changes_to_apply = self ._collect_updates (
314+ new_state , original_changes
315+ )
310316 merge_models (self , document )
311317 apply_changes (changes_to_apply , self )
312318 elif merge_strategy == MergeStrategy .remote :
@@ -359,7 +365,9 @@ async def insert(
359365 ]
360366 )
361367 result = await self .get_motor_collection ().insert_one (
362- get_dict (self , to_db = True , keep_nulls = self .get_settings ().keep_nulls ),
368+ get_dict (
369+ self , to_db = True , keep_nulls = self .get_settings ().keep_nulls
370+ ),
363371 session = session ,
364372 )
365373 new_id = result .inserted_id
@@ -400,12 +408,16 @@ async def insert_one(
400408 :return: DocType
401409 """
402410 if not isinstance (document , cls ):
403- raise TypeError ("Inserting document must be of the original document class" )
411+ raise TypeError (
412+ "Inserting document must be of the original document class"
413+ )
404414 if bulk_writer is None :
405415 return await document .insert (link_rule = link_rule , session = session )
406416 else :
407417 if link_rule == WriteRules .WRITE :
408- raise NotSupported ("Cascade insert with bulk writing not supported" )
418+ raise NotSupported (
419+ "Cascade insert with bulk writing not supported"
420+ )
409421 bulk_writer .add_operation (
410422 Operation (
411423 operation = InsertOne ,
@@ -436,7 +448,9 @@ async def insert_many(
436448 :return: InsertManyResult
437449 """
438450 if link_rule == WriteRules .WRITE :
439- raise NotSupported ("Cascade insert not supported for insert many method" )
451+ raise NotSupported (
452+ "Cascade insert not supported for insert many method"
453+ )
440454 documents_list = [
441455 get_dict (
442456 document ,
@@ -563,7 +577,9 @@ async def save(
563577 LinkTypes .OPTIONAL_BACK_DIRECT ,
564578 ]:
565579 if isinstance (value , Document ):
566- await value .save (link_rule = link_rule , session = session )
580+ await value .save (
581+ link_rule = link_rule , session = session
582+ )
567583 if field_info .link_type in [
568584 LinkTypes .LIST ,
569585 LinkTypes .OPTIONAL_LIST ,
@@ -573,7 +589,9 @@ async def save(
573589 if isinstance (value , List ):
574590 await asyncio .gather (
575591 * [
576- obj .save (link_rule = link_rule , session = session )
592+ obj .save (
593+ link_rule = link_rule , session = session
594+ )
577595 for obj in value
578596 if isinstance (obj , Document )
579597 ]
@@ -661,10 +679,14 @@ async def replace_many(
661679 """
662680 ids_list = [document .id for document in documents ]
663681 if await cls .find (In (cls .id , ids_list )).count () != len (ids_list ):
664- raise ReplaceError ("Some of the documents are not exist in the collection" )
682+ raise ReplaceError (
683+ "Some of the documents are not exist in the collection"
684+ )
665685 async with BulkWriter (session = session ) as bulk_writer :
666686 for document in documents :
667- await document .replace (bulk_writer = bulk_writer , session = session )
687+ await document .replace (
688+ bulk_writer = bulk_writer , session = session
689+ )
668690
669691 @wrap_with_actions (EventTypes .UPDATE )
670692 @save_state_after
@@ -1099,14 +1121,18 @@ async def inspect_collection(
10991121 :return: InspectionResult
11001122 """
11011123 inspection_result = InspectionResult ()
1102- async for json_document in cls .get_motor_collection ().find ({}, session = session ):
1124+ async for json_document in cls .get_motor_collection ().find (
1125+ {}, session = session
1126+ ):
11031127 try :
11041128 parse_model (cls , json_document )
11051129 except ValidationError as e :
11061130 if inspection_result .status == InspectionStatuses .OK :
11071131 inspection_result .status = InspectionStatuses .FAIL
11081132 inspection_result .errors .append (
1109- InspectionError (document_id = json_document ["_id" ], error = str (e ))
1133+ InspectionError (
1134+ document_id = json_document ["_id" ], error = str (e )
1135+ )
11101136 )
11111137 return inspection_result
11121138
@@ -1179,7 +1205,9 @@ async def distinct(
11791205 session : Optional [ClientSession ] = None ,
11801206 ** kwargs : Any ,
11811207 ) -> list :
1182- return await cls .get_motor_collection ().distinct (key , filter , session , ** kwargs )
1208+ return await cls .get_motor_collection ().distinct (
1209+ key , filter , session , ** kwargs
1210+ )
11831211
11841212 @classmethod
11851213 def link_from_id (cls , id : Any ):
@@ -1270,7 +1298,9 @@ def find_many( # type: ignore
12701298 nesting_depths_per_field : Optional [Dict [str , int ]] = None ,
12711299 ** pymongo_kwargs ,
12721300 ) -> Union [FindMany [FindType ], FindMany ["DocumentProjectionType" ]]:
1273- args = cls ._add_class_id_filter (args , with_children ) + ({"deleted_at" : None },)
1301+ args = cls ._add_class_id_filter (args , with_children ) + (
1302+ {"deleted_at" : None },
1303+ )
12741304 return cls ._find_many_query_class (document_model = cls ).find_many (
12751305 * args ,
12761306 sort = sort ,
@@ -1299,7 +1329,9 @@ def find_one( # type: ignore
12991329 nesting_depths_per_field : Optional [Dict [str , int ]] = None ,
13001330 ** pymongo_kwargs ,
13011331 ) -> Union [FindOne [FindType ], FindOne ["DocumentProjectionType" ]]:
1302- args = cls ._add_class_id_filter (args , with_children ) + ({"deleted_at" : None },)
1332+ args = cls ._add_class_id_filter (args , with_children ) + (
1333+ {"deleted_at" : None },
1334+ )
13031335 return cls ._find_one_query_class (document_model = cls ).find_one (
13041336 * args ,
13051337 projection_model = projection_model ,
0 commit comments