Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BaseModelFormSet.save_m2m: accept self #970

Merged
merged 2 commits into from
May 27, 2022

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented May 25, 2022

Before it would result in the following when calling it:

Attribute function "save_m2m" with type "Callable[[], None]" does not accept self argument [misc]

Originally added in https://github.com/typeddjango/django-stubs/pull/909/files#diff-3201a55e0a4a5182b8e53740898a55b982ca9c47806c4d4d7be224c1c68bcb39R152

/cc @sterliakov (Thanks for this great update btw!)

Before it would result in the following when calling it:

> Attribute function "save_m2m" with type "Callable[[], None]" does not accept self argument  [misc]
@@ -150,7 +150,7 @@ class BaseModelFormSet(Generic[_M, _ModelFormT], BaseFormSet[_ModelFormT]):
def save_existing(self, form: _ModelFormT, instance: _M, commit: bool = ...) -> _M: ...
def delete_existing(self, obj: _M, commit: bool = ...) -> None: ...
saved_forms: List[_ModelFormT] = ...
save_m2m: Callable[[], None] = ...
save_m2m: Callable[[self], None] = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myabe we should re-write it as def save_m2m?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done.

Note that it is a method that will only be there when commit=False is used before, but I think that cannot be reflected really.

@@ -150,7 +150,7 @@ class BaseModelFormSet(Generic[_M, _ModelFormT], BaseFormSet[_ModelFormT]):
def save_existing(self, form: _ModelFormT, instance: _M, commit: bool = ...) -> _M: ...
def delete_existing(self, obj: _M, commit: bool = ...) -> None: ...
saved_forms: List[_ModelFormT] = ...
save_m2m: Callable[[self], None] = ...
def save_m2m(self) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: I think that confusion came from these lines: https://github.com/django/django/blob/8c0886b068ba4e224dd78104b93c9638b860b398/django/forms/models.py#L781-L785

But, this is indeed a instance-level method. So, self is there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants