diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index a7fe1961..8ccc2bc5 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -608,15 +608,17 @@ def is_attribute(node): def is_model_view_subclass_method_shouldnt_be_function(node): """Checks that node is get or post method of the View class.""" if node.name not in ('get', 'post'): - return False parent = node.parent while parent and not isinstance(parent, ScopedClass): parent = parent.parent - subclass = '.View' - return parent is not None and parent.name.endswith('View') and node_is_subclass(parent, subclass) + subclass = ('django.views.View', + 'django.views.generic.View', + 'django.views.generic.base.View',) + + return parent is not None and node_is_subclass(parent, *subclass) def is_model_view_subclass_unused_argument(node): @@ -635,7 +637,7 @@ def is_argument_named_request(node): """ If an unused-argument is named 'request' ignore that! """ - return 'request'in node.argnames() + return 'request' in node.argnames() def is_model_field_display_method(node): @@ -795,7 +797,7 @@ def apply_augmentations(linter): # View # Method could be a function (get, post) - suppress_message(linter, ClassChecker.leave_functiondef, 'R0201', + suppress_message(linter, ClassChecker.leave_functiondef, 'no-self-use', is_model_view_subclass_method_shouldnt_be_function) # Unused argument 'request' (get, post) suppress_message(linter, VariablesChecker.leave_functiondef, 'unused-argument', diff --git a/pylint_django/tests/input/func_noerror_classviews.py b/pylint_django/tests/input/func_noerror_classviews.py index b37b101d..eaf98e28 100644 --- a/pylint_django/tests/input/func_noerror_classviews.py +++ b/pylint_django/tests/input/func_noerror_classviews.py @@ -4,7 +4,8 @@ """ # pylint: disable=missing-docstring -from django.views.generic import TemplateView +from django.http import JsonResponse +from django.views.generic import TemplateView, View class BoringView(TemplateView): @@ -15,3 +16,10 @@ def get_context_data(self, **kwargs): 'args': self.args, 'kwargs': self.kwargs } + + +class JsonView(View): + def post(self, request): + # do something with objects but don't use + # self or request + return JsonResponse({'rc': 0, 'response': 'ok'})