Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional suppressions for classes #396

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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()
4 changes: 4 additions & 0 deletions pylint_django/tests/input/external_drf_noerror_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
class TestSerializerSubclass(serializers.ModelSerializer):
class Meta:
pass


class TestSerializer(serializers.Serializer):
pass
10 changes: 10 additions & 0 deletions pylint_django/tests/input/func_noerror_docstrings.py
Original file line number Diff line number Diff line change
@@ -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()