Package: pylint-django
Aboutpylint-djangois aPylintplugin for improving code
analysis when analysing code using Django. It is also used by theProspectortool.InstallationTo install:pip install pylint-djangoWARNING:pylint-djangowill not installDjangoby default because
this causes more trouble than good,see discussion. If you wish
to automatically install the latest version ofDjangothen:pip install pylint-django[with-django]otherwise sort out your testing environment and pleaseDO NOTreport issues
about missing Django!UsageEnsurepylint-djangois installed and on your path. In order to access some
of the internal Django features to improve pylint inspections, you should also
provide a Django settings module appropriate to your project. This can be done
either with an environment variable:DJANGO_SETTINGS_MODULE=your.app.settings pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>Alternatively, this can be passed in as a commandline flag:pylint --load-plugins pylint_django --django-settings-module=your.app.settings [..other options..] <path_to_your_sources>If you do not configure Django, default settings will be used but this will not include, for
example, which applications to include inINSTALLED_APPSand so the linting and type inference
will be less accurate. It is recommended to specify a settings module.ProspectorIf you haveprospectorinstalled, thenpylint-djangowill already be
installed as a dependency, and will be activated automatically if Django is
detected:prospector [..other options..]FeaturesPrevents warnings about Django-generated attributes such asModel.objectsorViews.request.Prevents warnings when usingForeignKeyattributes (“Instance of
ForeignKey has no <x> member”).Fixes pylint’s knowledge of the types of Model and Form field attributesValidatesModel.__unicode__methods.Metainformational classes on forms and models do not generate errors.Flags dangerous use of the exclude attribute in ModelForm.Meta.Uses Django’s internal machinery to try and resolve models referenced as
strings in ForeignKey fields. That relies ondjango.setup()which needs
the appropriate project settings defined!Additional pluginspylint_django.checkers.migrationslooks for migrations which:add new model fields and these fields have a default value. According toDjango docsthis may have performance penalties especially on large tables. The preferred way
is to add a new DB column withnull=Truebecause it will be created instantly
and then possibly populate the table with the desired default values.
Only the last migration from a sub-directory will be examined;aremigrations.RunPython()without a reverse callable - these will result in
non reversible data migrations;This plugin is disabled by default! To enable it:pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.migrationsContributingPlease feel free to add your name to theCONTRIBUTORS.rstfile if you want to
be credited when pull requests get merged. You can also add to theCHANGELOG.rstfile if you wish, although we’ll also do that when merging.TestsThe structure of the test package follows that from pylint itself.It is fairly simple: create a module starting withfunc_followed by
a test name, and insert into it some code. The tests will run pylint
against these modules. If the idea is that no messages now occur, then
that is fine, just check to see if it works by runningscripts/test.sh.Any command line argument passed toscripts/test.shwill be passed to the internal invocation ofpytest.
For example if you want to debug the tests you can executescripts/test.sh--capture=no.
A specific test case can be run by filtering based on the file name of the test case./scripts/test.sh-k'func_noerror_views'.Ideally, add some pylint error suppression messages to the file to prevent
spurious warnings, since these are all tiny little modules not designed to
do anything so there’s no need to be perfect.It is possible to make tests with expected error output, for example, if
adding a new message or simply accepting that pylint is supposed to warn.
Atest_file_name.txtfile contains a list of expected error messages in the
formaterror-type:linenumber:class name or empty:1st line of detailed error text:confidence or empty.Licensepylint-djangois available under the GPLv2 license.