|
9 | 9 | from astroid.nodes.scoped_nodes import Module
|
10 | 10 | from astroid.objects import Super
|
11 | 11 | from django import VERSION as django_version
|
| 12 | +from django.conf import settings |
12 | 13 | from django.utils import termcolors
|
13 | 14 | from django.views.generic.base import ContextMixin, RedirectView, View
|
14 | 15 | from django.views.generic.dates import DateMixin, DayMixin, MonthMixin, WeekMixin, YearMixin
|
@@ -752,6 +753,23 @@ def allow_meta_protected_access(node):
|
752 | 753 | return False
|
753 | 754 |
|
754 | 755 |
|
| 756 | +def allow_simple_history_protected_access(assign_node): |
| 757 | + # NOTE: Only consider the first assignment target, mirroring current pylint behavior. |
| 758 | + # See pylint ClassChecker::visit_assign(). |
| 759 | + # Because the type of assign_target typically cannot be inferred, this will suppress |
| 760 | + # the warning even in assignments on objects not related to simple_history. |
| 761 | + assign_target = assign_node.targets[0] |
| 762 | + assign_target_attrname = getattr(assign_target, "attrname", None) |
| 763 | + |
| 764 | + if assign_target_attrname is None or assign_target_attrname not in ("_change_reason",): |
| 765 | + return False |
| 766 | + |
| 767 | + if "simple_history" not in settings.INSTALLED_APPS: |
| 768 | + return False |
| 769 | + |
| 770 | + return True |
| 771 | + |
| 772 | + |
755 | 773 | class IsClass: # pylint: disable=too-few-public-methods
|
756 | 774 | def __init__(self, class_name):
|
757 | 775 | self.class_name = class_name
|
@@ -968,6 +986,14 @@ def apply_augmentations(linter):
|
968 | 986 | is_model_mpttmeta_subclass,
|
969 | 987 | )
|
970 | 988 |
|
| 989 | + # django-simple-history |
| 990 | + suppress_message( |
| 991 | + linter, |
| 992 | + ClassChecker.visit_assign, |
| 993 | + "protected-access", |
| 994 | + allow_simple_history_protected_access, |
| 995 | + ) |
| 996 | + |
971 | 997 | # factory_boy's DjangoModelFactory
|
972 | 998 | suppress_message(linter, TypeChecker.visit_attribute, "no-member", is_model_factory)
|
973 | 999 | suppress_message(
|
|
0 commit comments