PyLint richtig einstellen?

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Benutzeravatar
TheGrudge
User
Beiträge: 96
Registriert: Donnerstag 4. Mai 2006, 18:39

Hallo,

habe ein Problem mit PyLint und Pydev-Eclipse.
Ich schreibe ein Django-Project und habe dort Klassen erstellt, die von models.Model abgeleitet wurden.
Nun beschwert sich PyLint aber bei jeder dieser Klassen, das es z.B. das member "objects" nicht gibt, obwohl das nicht stimmt.
ID:E1101 _sendmail: Class 'MailNotification' has no 'objects' member
Hier mal die Klassendefinition:

Code: Alles auswählen

from django.db import models

class MailNotification(models.Model):
    name = models.CharField(maxlength=100,
                help_text="shortname of the MailNotification. This name " \
                "is used as an unique ID for database searches.")
    mail_to = models.EmailField(
                help_text="recipient mail address")
    mail_from = models.EmailField(blank=True,
                help_text="optional: sender mail address")
    timeout = models.IntegerField(blank=True, null=True,
                  help_text="optional: timeout in minutes")
    subject = models.CharField(maxlength=200,
                  help_text="subject for mail.")
    message = models.TextField(
                  help_text="the mail message.<br/>" \
                  "If you define the mail for " \
                  "<b>logged in users</b>, please note that there are 2 " \
                  "variables which can be replaced with custom data:<br/>" \
                  "<br/>" \
                  "<b><USER></b>: will be replaced with " \
                  "current user name<br/> " \
                  "<b><USER_ID></b>: will be replaced with " \
                  "the database ID " \
                  "of the current user")
    class Admin:
        list_display = ('name', 'subject', 'message')
        ordering = ['name']

    def __str__(self):
        return self.name
Und der Aufruf, um ein MailNotification-Objekt aus der Datenbank zu laden:

Code: Alles auswählen

mail = MailNotification.objects.get(name='logged_in_users')
Ist es möglich PyLint zu sagen das es auch in der Superklasse models.Model nachschauen soll?
Benutzeravatar
sunmountain
User
Beiträge: 89
Registriert: Montag 13. März 2006, 17:18

2.3. Invoking pylint
Pylint is meant to be called from the commant line. The usage is
pylint [options] module_or_package
You should give pylint the name of a Python package or module. Pylint will import this package or module, so you should pay attention to your PYTHONPATH, since it is a common error to analyze an installed version of a module instead of the development version.
It is also possible to analyze python files, with a few restriction. The thing to keep in mind is that pylint will try to convert the file name to a module name, and only be able to process the file if it succeeds.
pylint mymodule.py
should always works since the current working directory is automatically added on top of the python path
pylint directory/mymodule.py
will work if "directory" is a python package (i.e. has an __init__.py file) or if "directory" is in the python path.
[/quote]
Benutzeravatar
TheGrudge
User
Beiträge: 96
Registriert: Donnerstag 4. Mai 2006, 18:39

Ja und nun? Wie ich das aufrufe weiß ich, aber er meckert das meine Klasse diese Member nicht hat, obwohl django und auch mein project im Pythonpath liegt.
BlackJack

Die Frage ist wie ein `models.Model` zu dem `objects`-Attribut kommt. Bei Webframeworks wird oft ein bisschen "Magie" eingesetzt wie Metaklassen oder das diese Attribute auf andere Weise erst dynamisch zur Laufzeit zugewiesen werden. Da kommt ein statisches Prüfprogramm einfach ab einer gewissen Stelle nicht mehr mit.
Benutzeravatar
TheGrudge
User
Beiträge: 96
Registriert: Donnerstag 4. Mai 2006, 18:39

ah ok, hmm wie django das macht weiss ich leider auch nicht.
Ich nehme PyLint erst einmal nur für Convention-Tests, sprich das Einhalten der PEP008.
Danach schaue ich mal weiter...
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

TheGrudge hat geschrieben:ah ok, hmm wie django das macht weiss ich leider auch nicht.
Das wird in django/db/models/manager.py gemacht, d.h. es wird, wenn objects nicht definiert wird, der Standardmanager benutzt. objects wird aber zur Laufzeit in die Klasse eingefügt, also könnte PyLint da durchaus Probleme haben.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten