Skip to content

Commit

Permalink
Disable unused-argument request for views. Fix #155
Browse files Browse the repository at this point in the history
in fact we disable this error just based on the argument name.
For functions it is not really possible to reliably determine if
the function is a real view that serves http requests or a
plain-old-function (maybe a helper) where the argument was named
'request'.
  • Loading branch information
atodorov committed May 24, 2018
1 parent efd0404 commit 19c2bc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,14 @@ def is_model_view_subclass_unused_argument(node):
if not is_model_view_subclass_method_shouldnt_be_function(node):
return False

return 'request' in node.argnames()
return is_argument_named_request(node)


def is_argument_named_request(node):
"""
If an unused-argument is named 'request' ignore that!
"""
return 'request'in node.argnames()


def is_model_field_display_method(node):
Expand Down Expand Up @@ -821,7 +828,8 @@ def apply_augmentations(linter):
# Method could be a function (get, post)
suppress_message(linter, _leave_function(ClassChecker), 'R0201', is_model_view_subclass_method_shouldnt_be_function)
# Unused argument 'request' (get, post)
suppress_message(linter, _leave_function(VariablesChecker), 'W0613', is_model_view_subclass_unused_argument)
suppress_message(linter, _leave_function(VariablesChecker), 'unused-argument', is_model_view_subclass_unused_argument)
suppress_message(linter, _leave_function(VariablesChecker), 'unused-argument', is_argument_named_request)

# django-mptt
suppress_message(linter, _visit_class(DocStringChecker), 'missing-docstring', is_model_mpttmeta_subclass)
Expand Down
8 changes: 8 additions & 0 deletions pylint_django/tests/input/func_noerror_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Checks that Pylint does not complain when using function based views.
"""
# pylint: disable=missing-docstring


def empty_view(request):
pass

0 comments on commit 19c2bc7

Please sign in to comment.