@@ -645,13 +645,13 @@ def is_model_test_case_subclass(node):
645
645
return node_is_subclass (node , "django.test.testcases.TestCase" )
646
646
647
647
648
- def generic_is_view_attribute (parents , attrs ):
649
- """Generates is_X_attribute function for given parents and attrs."""
648
+ class IsAttribute :
649
+ def __init__ (self , parents , attrs ):
650
+ self .parents = parents
651
+ self .attrs = attrs
650
652
651
- def is_attribute (node ):
652
- return _attribute_is_magic (node , attrs , parents )
653
-
654
- return is_attribute
653
+ def __call__ (self , node ):
654
+ return _attribute_is_magic (node , self .attrs , self .parents )
655
655
656
656
657
657
def is_model_view_subclass_method_shouldnt_be_function (node ):
@@ -756,9 +756,12 @@ def allow_meta_protected_access(node):
756
756
return False
757
757
758
758
759
- def is_class (class_name ):
760
- """Shortcut for node_is_subclass."""
761
- return lambda node : node_is_subclass (node , class_name )
759
+ class IsClass :
760
+ def __init__ (self , class_name ):
761
+ self .class_name = class_name
762
+
763
+ def __call__ (self , node ):
764
+ return node_is_subclass (node , self .class_name )
762
765
763
766
764
767
def wrap (orig_method , with_method ):
@@ -858,37 +861,37 @@ def apply_augmentations(linter):
858
861
linter ,
859
862
TypeChecker .visit_attribute ,
860
863
"no-member" ,
861
- generic_is_view_attribute (parents , attrs ),
864
+ IsAttribute (parents , attrs ),
862
865
)
863
866
864
867
# formviews have too many ancestors, there's nothing the user of the library can do about that
865
868
suppress_message (
866
869
linter ,
867
870
MisdesignChecker .visit_classdef ,
868
871
"too-many-ancestors" ,
869
- is_class ("django.views.generic.edit.FormView" ),
872
+ IsClass ("django.views.generic.edit.FormView" ),
870
873
)
871
874
872
875
# class-based generic views just have a longer inheritance chain
873
876
suppress_message (
874
877
linter ,
875
878
MisdesignChecker .visit_classdef ,
876
879
"too-many-ancestors" ,
877
- is_class ("django.views.generic.detail.BaseDetailView" ),
880
+ IsClass ("django.views.generic.detail.BaseDetailView" ),
878
881
)
879
882
suppress_message (
880
883
linter ,
881
884
MisdesignChecker .visit_classdef ,
882
885
"too-many-ancestors" ,
883
- is_class ("django.views.generic.edit.ProcessFormView" ),
886
+ IsClass ("django.views.generic.edit.ProcessFormView" ),
884
887
)
885
888
886
889
# model forms have no __init__ method anywhere in their bases
887
890
suppress_message (
888
891
linter ,
889
892
ClassChecker .visit_classdef ,
890
893
"W0232" ,
891
- is_class ("django.forms.models.ModelForm" ),
894
+ IsClass ("django.forms.models.ModelForm" ),
892
895
)
893
896
894
897
# Meta
0 commit comments