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
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
Unreleased
----------

- Start testing with Django 3.2 on Python 3.9
- Start testing with Django 3.2 on Python 3.9 (Michael K.)
- Teach pylint-django about all HTTP methods from the View class, not only
``get`` and ``post`` (Nicolás Quiroz)
- Ignore ``unused-argument`` for ``*args``, ``**kwards`` in view method signatures


Version 2.4.2 (08 Jan 2021)
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* [WayneLambert](https://github.com/WayneLambert)
* [alejandro-angulo](https://github.com/alejandro-angulo)
* [brymut](https://github.com/brymut)

* [michael-k](https://github.com/michael-k)
* [naquiroz](https://github.com/naquiroz)
6 changes: 3 additions & 3 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ 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'):
"""Checks that node is a default http method (i.e get, post, put, and more) of the View class."""
if node.name not in View.http_method_names:
return False

parent = node.parent
Expand All @@ -652,7 +652,7 @@ def ignore_unused_argument_warnings_for_request(orig_method, self, stmt, name):
The signature of Django view functions require the request argument but it is okay if the request is not used.
This function should be used as a wrapper for the `VariablesChecker._is_name_ignored` method.
"""
if name == 'request':
if name in ('request', 'args', 'kwargs'):
return True

return orig_method(self, stmt, name)
Expand Down
53 changes: 51 additions & 2 deletions pylint_django/tests/input/func_noerror_classviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,57 @@ def get_context_data(self, **kwargs):
}


class JsonView(View):
def post(self, request):
class JsonGetView(View):
def get(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonPostView(View):
def post(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonPutView(View):
def put(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonPatchView(View):
def patch(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonDeleteView(View):
def delete(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonHeadView(View):
def head(self, request, *args, **kwargs): # pylint: disable=method-hidden
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonOptionsView(View):
def options(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})


class JsonTraceView(View):
def trace(self, request, *args, **kwargs):
# do something with objects but don't use
# self or request
return JsonResponse({'rc': 0, 'response': 'ok'})
Expand Down