Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions mypy_django_plugin/transformers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
AssignmentStmt,
CallExpr,
Context,
Expression,
FakeInfo,
NameExpr,
RefExpr,
Expand Down Expand Up @@ -908,22 +907,9 @@ def resolve_many_to_many_arguments(self, call: CallExpr, /, context: Context) ->
Inspect a 'ManyToManyField(...)' call to collect argument data on any 'to' and
'through' arguments.
"""
look_for: dict[str, Expression | None] = {"to": None, "through": None}
# Look for 'to', being declared as the first positional argument
if call.arg_kinds[0].is_positional():
look_for["to"] = call.args[0]
# Look for 'through', being declared as the sixth positional argument.
if len(call.args) > 5 and call.arg_kinds[5].is_positional():
look_for["through"] = call.args[5]

# Sort out if any of the expected arguments was provided as keyword arguments
for arg_expr, _arg_kind, arg_name in zip(call.args, call.arg_kinds, call.arg_names, strict=False):
if arg_name in look_for and look_for[arg_name] is None:
look_for[arg_name] = arg_expr

# 'to' is a required argument of 'ManyToManyField()', we can't do anything if it's not provided
to_arg = look_for["to"]
to_arg = helpers.get_class_init_argument_by_name(call, "to")
if to_arg is None:
# 'to' is a required argument of 'ManyToManyField()', we can't do anything if it's not provided
return None

# Resolve the type of the 'to' argument expression
Expand All @@ -939,7 +925,7 @@ def resolve_many_to_many_arguments(self, call: CallExpr, /, context: Context) ->
)

# Resolve the type of the 'through' argument expression
through_arg = look_for["through"]
through_arg = helpers.get_class_init_argument_by_name(call, "through")
through = None
if through_arg is not None:
through_model = helpers.get_model_from_expression(
Expand Down
Loading