1414 AssignmentStmt ,
1515 CallExpr ,
1616 Context ,
17- Expression ,
1817 FakeInfo ,
1918 NameExpr ,
2019 RefExpr ,
@@ -908,22 +907,9 @@ def resolve_many_to_many_arguments(self, call: CallExpr, /, context: Context) ->
908907 Inspect a 'ManyToManyField(...)' call to collect argument data on any 'to' and
909908 'through' arguments.
910909 """
911- look_for : dict [str , Expression | None ] = {"to" : None , "through" : None }
912- # Look for 'to', being declared as the first positional argument
913- if call .arg_kinds [0 ].is_positional ():
914- look_for ["to" ] = call .args [0 ]
915- # Look for 'through', being declared as the sixth positional argument.
916- if len (call .args ) > 5 and call .arg_kinds [5 ].is_positional ():
917- look_for ["through" ] = call .args [5 ]
918-
919- # Sort out if any of the expected arguments was provided as keyword arguments
920- for arg_expr , _arg_kind , arg_name in zip (call .args , call .arg_kinds , call .arg_names , strict = False ):
921- if arg_name in look_for and look_for [arg_name ] is None :
922- look_for [arg_name ] = arg_expr
923-
924- # 'to' is a required argument of 'ManyToManyField()', we can't do anything if it's not provided
925- to_arg = look_for ["to" ]
910+ to_arg = helpers .get_class_init_argument_by_name (call , "to" )
926911 if to_arg is None :
912+ # 'to' is a required argument of 'ManyToManyField()', we can't do anything if it's not provided
927913 return None
928914
929915 # Resolve the type of the 'to' argument expression
@@ -939,7 +925,7 @@ def resolve_many_to_many_arguments(self, call: CallExpr, /, context: Context) ->
939925 )
940926
941927 # Resolve the type of the 'through' argument expression
942- through_arg = look_for [ "through" ]
928+ through_arg = helpers . get_class_init_argument_by_name ( call , "through" )
943929 through = None
944930 if through_arg is not None :
945931 through_model = helpers .get_model_from_expression (
0 commit comments