diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index e067709d..85bff5f8 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -797,6 +797,27 @@ 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 +1013,15 @@ 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() 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..91e7c753 --- /dev/null +++ b/pylint_django/tests/input/func_noerror_docstrings.py @@ -0,0 +1,10 @@ +# 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()