diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index c8e31b4b..ccedb7ad 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -313,6 +313,14 @@ def apply_augmentations(linter): suppress_message(linter, ClassChecker.visit_class, 'W0232', is_model_media_subclass) suppress_message(linter, MisdesignChecker.leave_class, 'R0903', is_model_media_subclass) + # Too few public methods started appearing for Views and Models as part of Pylint>=1.4 / astroid>=1.3.3 + # Not sure why, suspect this is a failure to get the parent classes somewhere + # For now, just suppress it on models and views + suppress_message(linter, MisdesignChecker.leave_class, 'R0903', is_class('django.db.models.base.Model')) + # TODO: why does this not work with the fqn of 'View'? Must be something to do with the overriding and transforms + suppress_message(linter, MisdesignChecker.leave_class, 'R0903', is_class('.View')) + + # Admin # Too many public methods (40+/20) # TODO: Count public methods of django.contrib.admin.options.ModelAdmin and increase diff --git a/pylint_django/transforms/fields.py b/pylint_django/transforms/fields.py index d9f4a2f6..a08ab9b6 100644 --- a/pylint_django/transforms/fields.py +++ b/pylint_django/transforms/fields.py @@ -1,4 +1,4 @@ -from astroid import MANAGER, scoped_nodes, nodes +from astroid import MANAGER, scoped_nodes, nodes, inference_tip _STR_FIELDS = ('CharField', 'SlugField', 'URLField', 'TextField', 'EmailField', @@ -17,7 +17,12 @@ def is_form_field(cls): return cls.qname().startswith('django.forms.fields') -def make_field_str(cls): +def is_model_or_form_field(cls): + return is_model_field(cls) or is_form_field(cls) + + +def apply_type_shim(cls, context=None): + if cls.name in _STR_FIELDS: base_node = scoped_nodes.builtin_lookup('str') elif cls.name in _INT_FIELDS: @@ -35,12 +40,10 @@ def make_field_str(cls): elif cls.name == 'DateField': base_node = MANAGER.ast_from_module_name('datetime').lookup('date') else: - return cls + return iter([cls]) - cls.bases.append(base_node[1][0]) - return cls + return iter([cls] + base_node[1]) def add_transforms(manager): - manager.register_transform(nodes.Class, make_field_str, is_model_field) - manager.register_transform(nodes.Class, make_field_str, is_form_field) + manager.register_transform(nodes.Class, inference_tip(apply_type_shim), is_model_or_form_field)