-
-
Notifications
You must be signed in to change notification settings - Fork 484
Incompatible with django-configurations due to the way the settings are imported #417
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
Maybe we can provide a configuration option that leads to a some function hook? [mypy.plugins.django-stubs]
init-hook = my.custom.function # my/custom.py
def function():
import configurations
configurations.setup() This will solve your (and possibly all other problems). |
Great idea! It's also inline with
I reckon that a config option is enough - no need to support an environmental var, since it's not something that changes between environments or different dev setups considering a single project. Are you by any chance aware of any side effects that this may cause? The function above calls Also, having patched the current master (instead of try:
import configurations
configurations.setup()
except ModuleNotFoundError:
settings.pre_setup() Though there have been some significant changes merged into master so I'm not very surprised. Hope it won't get too involved. |
The good thing we allow any side-effects during the setup phase 😆 Joking aside, I don't think there will be any. Because we already use |
It's a lovely one - mypy ends up showing a single error instead of a couple of hundred :D Just released there was a PR intending to solve this issue: #180. Though it looks like it's stale now and wasn't exactly what you'd expect to have here. Just for clarification, I guess your requirements haven't changed, right? |
Yes, I still believe that we should not add any support for third-party libraries here. |
Surely not. Cool, that's great. I'll get this done in the eve. |
I'm getting that error when trying to run mypy in my project... |
any update? |
For anyone who comes here – this non-intrusive workaround #180 (comment) written by @wlf100220 might help you. |
Bug report
🐛
What's wrong
Trying to use
django-stubs
together withdjango-configurations
is a big pain since the latter interferes and controls how django settings are loaded. By default, the following exception gets thrown when trying to runmypy
:That makes sense, since
configurations
disallows loading the settings manually and requires to run these two calls to configure django, both of them are for example found inmanage.py
andwsgi.py
:mypy configuration in setup.cfg (it follows
[metadata]
and[options]
package metadata definitions)I tried looking for a workaround which didn't involve changing neither
mypy
nordjango-stubs
, nordjango-configurations
source files and I'm afraid I have failed. Unfortunately this also blocks DRF stubs from being useful.How is that should be
django-configurations
should be supported and allowed to load django settings if the user uses it (unless it is somehow incompatible with the way the stubs are generated?).System information
python
version:3.6.9
django
version:2.2.14
mypy
version:0.770
django-stubs
version:1.5.0
django-configurations
version:2.2
Possible solution
One of possible options would be to include those two calls in
mypy_django_plugin.django.context
initialize_django
call, just before themodels
get imported:I found that this works for me - though I haven't tested it extensively yet. I'd be happy to add a PR for this upon your confirmation.
The text was updated successfully, but these errors were encountered: