Issue #24 resolved

E1002 message for django.forms.ModelForm subclasses, even under Python 3

created an issue

Python 3 test code:

from django import forms
from .models import MyModel

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = ("test",)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

Pylint 0.25.1 generates: E1002 'Use of super on an old style class' message which is wrong, because:

  1. This is a new-style class in Django (which heavily uses metaclasses)
  2. I am using Python 3. There are no 'old style classes' in Python 3 at all.

The problem is also discussed on StackOverflow:

Comments (18)

  1. adrian_flanagan

    Found a simple demonstration example:

    from collections import MutableMapping
    class CustomMapping(MutableMapping):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

    This triggers E1002 for me in python 3.3.2.

    default configuration, pylint 1.0.0, astroid 1.0.1, common 0.60.0, Python 3.3.2+ (default, Oct 9 2013, 14:50:09) [GCC 4.8.1]

  2. Claudiu Popa

    Hm, actually not. Although right now I'm not sure that this is from pylint or from astroid. For instance, after infering all the bases, MyForm.ModelForm.ModelFormMetaclass is in fact newstyle. So the problem could actually be inside the newstyle property for Class nodes. I'll investigate further.

  3. Log in to comment