Skip to content

Commit eb6f5a4

Browse files
committed
Added additional suppressions for classes
1 parent b8217c1 commit eb6f5a4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,28 @@ def is_wsgi_application(node):
797797
)
798798

799799

800+
def is_drf_serializer(node):
801+
"""If class is child of DRF Serializer, it does not have to override create and update methods"""
802+
return node_is_subclass(node, "rest_framework.serializers.Serializer")
803+
804+
805+
806+
def has_different_docstring(node):
807+
"""Checks if function of child class has different docstring than parent"""
808+
parent = node.parent.frame()
809+
meth_node = None
810+
if isinstance(parent, ClassDef):
811+
for overridden in parent.local_attr_ancestors(node.name):
812+
try:
813+
meth_node = overridden[node.name]
814+
except KeyError:
815+
continue
816+
if meth_node.doc != node.doc:
817+
return True
818+
return False
819+
return False
820+
821+
800822
# Compat helpers
801823
def pylint_newstyle_classdef_compat(linter, warning_name, augment):
802824
if not hasattr(NewStyleConflictChecker, "visit_classdef"):
@@ -992,4 +1014,17 @@ def apply_augmentations(linter):
9921014
# wsgi.py
9931015
suppress_message(linter, NameChecker.visit_assignname, "invalid-name", is_wsgi_application)
9941016

1017+
# different docstings
1018+
suppress_message(
1019+
linter,
1020+
ClassChecker.visit_functiondef,
1021+
"useless-super-delegation",
1022+
has_different_docstring,
1023+
)
1024+
1025+
# not overriding creade and update in DRF Serializer class
1026+
suppress_message(
1027+
linter, ClassChecker.visit_classdef, "abstract-method", is_drf_serializer
1028+
)
1029+
9951030
apply_wrapped_augmentations()

0 commit comments

Comments
 (0)