Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 9 additions & 1 deletion pylint_django/tests/input/func_noerror_classviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'})