[New Rule][Django] Verify that settings
is correctly imported
#12200
Labels
rule
Implementing or modifying a lint rule
settings
is correctly imported
#12200
I'd like to add a rule for Django projects. I'm not quite sure about where to add it (If backwards capability was not an issue, I would add it to DJ)
What it could do
Verify that
settings
is correctly imported fromdjango.conf
.An unsafe fix could exist, as some code might depend on the side effects of importing the module (even though import side-effects are considered poor practice).
Why is this bad?
The Django Docs state that one should import
settings
fromdjango.conf
.It is an object (not a module) that is safe to access. Importing settings directly from the project could trigger side-effects.
Also,
django.conf.settings
abstracts the concepts of default settings and site-specific settings; it presents a single interface. It also decouples the code that uses settings from the location of the settings.Example
Incorrect:
Use instead:
I'm looking forward to your feedback.
The text was updated successfully, but these errors were encountered: