From eb6f5a43374ce1d2bf7b3efd219f17e26e26fa03 Mon Sep 17 00:00:00 2001 From: Konrad Wojda Date: Wed, 26 Apr 2023 10:37:40 +0900 Subject: [PATCH 1/3] Added additional suppressions for classes --- pylint_django/augmentations/__init__.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index e067709d..8a2659f3 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -797,6 +797,28 @@ def is_wsgi_application(node): ) +def is_drf_serializer(node): + """If class is child of DRF Serializer, it does not have to override create and update methods""" + return node_is_subclass(node, "rest_framework.serializers.Serializer") + + + +def has_different_docstring(node): + """Checks if function of child class has different docstring than parent""" + parent = node.parent.frame() + meth_node = None + if isinstance(parent, ClassDef): + for overridden in parent.local_attr_ancestors(node.name): + try: + meth_node = overridden[node.name] + except KeyError: + continue + if meth_node.doc != node.doc: + return True + return False + return False + + # Compat helpers def pylint_newstyle_classdef_compat(linter, warning_name, augment): if not hasattr(NewStyleConflictChecker, "visit_classdef"): @@ -992,4 +1014,17 @@ def apply_augmentations(linter): # wsgi.py suppress_message(linter, NameChecker.visit_assignname, "invalid-name", is_wsgi_application) + # different docstings + suppress_message( + linter, + ClassChecker.visit_functiondef, + "useless-super-delegation", + has_different_docstring, + ) + + # not overriding creade and update in DRF Serializer class + suppress_message( + linter, ClassChecker.visit_classdef, "abstract-method", is_drf_serializer + ) + apply_wrapped_augmentations() From 5d577bee1cdfaeaeb7016a9fc86280479ba75b7a Mon Sep 17 00:00:00 2001 From: Konrad Wojda Date: Wed, 26 Apr 2023 10:38:37 +0900 Subject: [PATCH 2/3] Added tests to new suppressions --- .../tests/input/external_drf_noerror_serializer.py | 4 ++++ pylint_django/tests/input/func_noerror_docstrings.py | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 pylint_django/tests/input/func_noerror_docstrings.py diff --git a/pylint_django/tests/input/external_drf_noerror_serializer.py b/pylint_django/tests/input/external_drf_noerror_serializer.py index 814678da..90cb9cf2 100644 --- a/pylint_django/tests/input/external_drf_noerror_serializer.py +++ b/pylint_django/tests/input/external_drf_noerror_serializer.py @@ -9,3 +9,7 @@ class TestSerializerSubclass(serializers.ModelSerializer): class Meta: pass + + +class TestSerializer(serializers.Serializer): + pass diff --git a/pylint_django/tests/input/func_noerror_docstrings.py b/pylint_django/tests/input/func_noerror_docstrings.py new file mode 100644 index 00000000..6ae596fe --- /dev/null +++ b/pylint_django/tests/input/func_noerror_docstrings.py @@ -0,0 +1,9 @@ +# pylint: disable=missing-class-docstring, missing-module-docstring, too-few-public-methods, missing-function-docstring, no-method-argument, no-self-use, too-many-function-args +class Parent: + def test(): + return 0 + +class ChildDoc(Parent): + def test(): + """Difference""" + return super().test() From 07165f8b9fe519a5928412a2b37477cb20300e24 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Apr 2023 01:47:42 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pylint_django/augmentations/__init__.py | 5 +---- pylint_django/tests/input/func_noerror_docstrings.py | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index 8a2659f3..85bff5f8 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -802,7 +802,6 @@ def is_drf_serializer(node): return node_is_subclass(node, "rest_framework.serializers.Serializer") - def has_different_docstring(node): """Checks if function of child class has different docstring than parent""" parent = node.parent.frame() @@ -1023,8 +1022,6 @@ def apply_augmentations(linter): ) # not overriding creade and update in DRF Serializer class - suppress_message( - linter, ClassChecker.visit_classdef, "abstract-method", is_drf_serializer - ) + suppress_message(linter, ClassChecker.visit_classdef, "abstract-method", is_drf_serializer) apply_wrapped_augmentations() diff --git a/pylint_django/tests/input/func_noerror_docstrings.py b/pylint_django/tests/input/func_noerror_docstrings.py index 6ae596fe..91e7c753 100644 --- a/pylint_django/tests/input/func_noerror_docstrings.py +++ b/pylint_django/tests/input/func_noerror_docstrings.py @@ -3,6 +3,7 @@ class Parent: def test(): return 0 + class ChildDoc(Parent): def test(): """Difference"""