Syntastic + Django
Asked Answered
A

2

11

I just started developing on Django, and then I thought using the Syntastic syntax checker on it would be a good idea.

The problem is that it complains about some things being wrong when, in fact, they aren't.

Examples:

  1. For

    from django.core.urlresolvers import reverse
    

    I get:

    error| [F0401] Unable to import 'django.core.urlresolvers'
    
  2. For

    amount = self.sale_set.filter(date__year=year).aggregate(sum=Sum('amount'))["sum"]
    

    I get (where self is an Album)

    error| [E1101, Album.get_sales_total] Instance of 'Album' has no 'sale_set' member
    

This code runs perfectly even with these "errors", but how can I make Syntastic behave correctly?

Amylaceous answered 22/8, 2012 at 13:37 Comment(2)
This should be a bug report to the developers of Syntastic, then.Historiographer
More likely a bug in flake8, pyflakes, or pylint as they're the default syntax checkers used by Syntastic.Aalto
C
5

piggybacking on @supervacuo's answer:

there is a way to get this working for syntastic and it's rather straightforward, if not easy to figure out for someone unfamiliar with syntastic options (like, say, me):

in your .vimrc, add this line:

let g:syntastic_python_pylint_args = "--load-plugins pylint_django"

of course, this does require pylint-django be installed in your environment

Copley answered 22/10, 2015 at 19:44 Comment(0)
T
4

Both of these messages come from pylint — you can see fuller explanations with pylint --help-msg=$ID, or on http://pylint-messages.wikidot.com/.

You can disable the checks with e.g. from django.core.urlresolvers import reverse # pylint: disable=F0401, but that gets tiresome pretty quickly.

There's a pylint plugin for Django which will definitely fix your E1101 (and I hope the F0401 too). Maybe have a go at installing the plugin and configuring Syntastic to use it?

Thruway answered 20/1, 2014 at 20:54 Comment(1)
Nice suggestion, but did not work for me. At least, within a virtualenv.Circe

© 2022 - 2024 — McMap. All rights reserved.