-
-
Notifications
You must be signed in to change notification settings - Fork 493
Add a test for missing generics in stubs #2659
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
Add a test for missing generics in stubs #2659
Conversation
ext/django_stubs_ext/patch.py
Outdated
# logger.warning( | ||
# "`SetPasswordMixin` and `SetUnusablePasswordMixin` where not patched, django need to be configured " | ||
# "for this to be possible. Make sure to use `django_stubs_ext.monkeypatch()` after `django.setup()`.", | ||
# ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is annoying, we cannot easily patch these 2 because we end up importing the User model and it crashes if django.setup()
was not called beforehand.
The recommendation from the readme to add the monkeypatch in the setting file might not be enough for this.
I commented the logs here for the moment because I'm not sure what is the best way to handle this (and if I add it, I need to find a way to silence this logger in test or it fails some snapshot)
Any idea on how to handle this @sobolevn ? (or @adamchainz maybe if you have some time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented a workaround for these symbols that seem to work on my django codebases.
If you use these generics, you'll have to rerun the monkeypatch after django is initialized.
We could also maybe expose another monkeypatch
func for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How long does it take to run this test in CI? (sorry, not from a work computer right now)
Locally it was ~230ms, ci not sure, I can activate pytest timings to check once I'm back home from my concert X) |
1-1.3s in ci !
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great starting point! Thanks a lot! It found many classes that we forgot to monkey patch :)
I have made things!
Followup to this discussion #2384 (comment)
This introduce a test ensuring every generic we define in stubs are generic at runtime too.
This also adds the missing ones (
SetPasswordForm
, discussed above, being one of them)See initial failing run