diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d05f7681..c12a328c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0cdc307a..f0151e7f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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) diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index 1dc332a3..770c51c4 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -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 @@ -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) diff --git a/pylint_django/tests/input/func_noerror_classviews.py b/pylint_django/tests/input/func_noerror_classviews.py index c34e738f..f8320940 100644 --- a/pylint_django/tests/input/func_noerror_classviews.py +++ b/pylint_django/tests/input/func_noerror_classviews.py @@ -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'})