Skip to content

Commit e4c8fc7

Browse files
committed
Disable unused-argument request for views. Fix #155
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'.
1 parent 4360d79 commit e4c8fc7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,14 @@ def is_model_view_subclass_unused_argument(node):
645645
if not is_model_view_subclass_method_shouldnt_be_function(node):
646646
return False
647647

648-
return 'request' in node.argnames()
648+
return is_argument_named_request(node)
649+
650+
651+
def is_argument_named_request(node):
652+
"""
653+
If an unused-argument is named 'request' ignore that!
654+
"""
655+
return 'request'in node.argnames()
649656

650657

651658
def is_model_field_display_method(node):
@@ -833,7 +840,9 @@ def apply_augmentations(linter):
833840
# Method could be a function (get, post)
834841
suppress_message(linter, _leave_function(ClassChecker), 'R0201', is_model_view_subclass_method_shouldnt_be_function)
835842
# Unused argument 'request' (get, post)
836-
suppress_message(linter, _leave_function(VariablesChecker), 'W0613', is_model_view_subclass_unused_argument)
843+
suppress_message(linter, _leave_function(VariablesChecker), 'unused-argument',
844+
is_model_view_subclass_unused_argument)
845+
suppress_message(linter, _leave_function(VariablesChecker), 'unused-argument', is_argument_named_request)
837846

838847
# django-mptt
839848
suppress_message(linter, _visit_class(DocStringChecker), 'missing-docstring', is_model_mpttmeta_subclass)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Checks that Pylint does not complain when using function based views.
3+
"""
4+
# pylint: disable=missing-docstring
5+
6+
7+
def empty_view(request):
8+
pass

0 commit comments

Comments
 (0)