-
-
Notifications
You must be signed in to change notification settings - Fork 485
FormMixin is incompatible with SuccessMessageMixin #79
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
Comments
Yes, I believe restricting |
This ensures that the order in which these mixins are included into a derrived class does not matter and ends up more accurately reflecting the return type of SuccessMessageMixin in the process (its code doesn't appear to enforce that the returned response is a redirect). This provides a fix to a secondary aspect of https://github.com/mkurnikov/django-stubs/issues/79.
Unfortunately that fix doesn't seem to completely resolve the issue for me. I'll put up a PR with a proposed fix. |
@PeterJCLaw Oh yeah, that makes sense I guess. Is there a way to use an ABC to make sure view-mixins have the right shape in typestubs? |
I'm not sure if that's possible in type stubs. I'd guess it probably is, though not a pattern I've seen. I'm guessing you mean something like this: # common.pyi
class _FormMixinCommon(abc.ABC):
def form_valid(self, ...): ...
# forms.pyi
from ...common import _FormMixinCommon
class FormMixin(_FormMixinCommon):
...
# forms.pyi
from ...common import _FormMixinCommon
class SuccessMessageMixin(_FormMixinCommon):
... I'm not sure whether that's any better than just duplicating the signature and adding a test (the latter being what I've done in that PR). I suspect that duplicating the signature is probably clearer and (at least for small numbers of duplicates) doesn't represent much maintenance burden. There's probably benefit in keeping the type definitions reasonably close to the shape of the actual source we're typing. Are there other places where you think the ABC pattern might be useful? (If it just ends up being this place I suspect it would be more confusing to readers.) |
This ensures that the order in which these mixins are included into a derrived class does not matter and ends up more accurately reflecting the return type of SuccessMessageMixin in the process (its code doesn't appear to enforce that the returned response is a redirect). This provides a fix to a secondary aspect of https://github.com/mkurnikov/django-stubs/issues/79.
Uh oh!
There was an error while loading. Please reload this page.
From what I can tell, the Django sources for these two are fine to be mixed together, however the type annotations seem to disagree:
I suspect that the signature of
FormMixin
is the one we want to use, so the fix is to updateSuccessMessageMixin
to match. (If you agree that's a good solution I'd be happy to put up a PR)The text was updated successfully, but these errors were encountered: