@@ -123,9 +123,10 @@ class ModelB(models.Model):
123
123
pass
124
124
else :
125
125
for cls in inferred :
126
- if (node_is_subclass (
127
- cls , 'django.db.models.manager.Manager' ) or
128
- node_is_subclass (cls , 'django.db.models.base.Model' )):
126
+ if (node_is_subclass (cls ,
127
+ 'django.db.models.manager.Manager' ,
128
+ 'django.db.models.base.Model' ,
129
+ '.Model' )):
129
130
# This means that we are looking at a subclass of models.Model
130
131
# and something is trying to access a <something>_set attribute.
131
132
# Since this could exist, we will return so as not to raise an
@@ -156,25 +157,31 @@ def is_model_media_subclass(node):
156
157
parents = ('django.contrib.admin.options.ModelAdmin' ,
157
158
'django.forms.widgets.Media' ,
158
159
'django.db.models.base.Model' ,
160
+ '.Model' , # for the transformed version used in this plugin
159
161
'django.forms.forms.Form' ,
160
- 'django.forms.models.ModelForm' )
161
- return any ([node_is_subclass (node .parent , parent ) for parent in parents ])
162
+ '.Form' ,
163
+ 'django.forms.models.ModelForm' ,
164
+ '.ModelForm' )
165
+ return node_is_subclass (node .parent , * parents )
162
166
163
167
164
168
def is_model_meta_subclass (node ):
165
169
"""Checks that node is derivative of Meta class."""
166
170
if node .name != 'Meta' or not isinstance (node .parent , Class ):
167
171
return False
168
172
169
- parents = ('django.db.models.base.Model' ,
173
+ parents = ('.Model' , # for the transformed version used here
174
+ 'django.db.models.base.Model' ,
175
+ '.Form' ,
170
176
'django.forms.forms.Form' ,
177
+ '.ModelForm' ,
171
178
'django.forms.models.ModelForm' ,
172
179
'rest_framework.serializers.ModelSerializer' ,
173
180
'rest_framework.generics.GenericAPIView' ,
174
181
'rest_framework.viewsets.ReadOnlyModelViewSet' ,
175
182
'rest_framework.viewsets.ModelViewSet' ,
176
183
'django_filters.filterset.FilterSet' ,)
177
- return any ([ node_is_subclass (node .parent , parent ) for parent in parents ] )
184
+ return node_is_subclass (node .parent , * parents )
178
185
179
186
180
187
def is_model_mpttmeta_subclass (node ):
@@ -183,9 +190,12 @@ def is_model_mpttmeta_subclass(node):
183
190
return False
184
191
185
192
parents = ('django.db.models.base.Model' ,
193
+ '.Model' , # for the transformed version used in this plugin
186
194
'django.forms.forms.Form' ,
187
- 'django.forms.models.ModelForm' )
188
- return any ([node_is_subclass (node .parent , parent ) for parent in parents ])
195
+ '.Form' ,
196
+ 'django.forms.models.ModelForm' ,
197
+ '.ModelForm' )
198
+ return node_is_subclass (node .parent , * parents )
189
199
190
200
191
201
def is_model_test_case_subclass (node ):
@@ -233,7 +243,7 @@ def is_model_field_display_method(node):
233
243
# blindly accepting get_*_display
234
244
try :
235
245
for cls in node .last_child ().infered ():
236
- if node_is_subclass (cls , 'django.db.models.base.Model' ):
246
+ if node_is_subclass (cls , 'django.db.models.base.Model' , '.Model' ):
237
247
return True
238
248
except InferenceError :
239
249
return False
@@ -354,8 +364,8 @@ def apply_augmentations(linter):
354
364
# For now, just suppress it on models and views
355
365
suppress_message (linter , _leave_class (MisdesignChecker ), 'too-few-public-methods' ,
356
366
is_class ('.Model' ))
357
- # TODO: why does this not work with the fqn of 'View'? Must be something to do with the overriding and transforms
358
- suppress_message ( linter , _leave_class ( MisdesignChecker ), 'too-few-public-methods' , is_class ('.View' ))
367
+ suppress_message ( linter , _leave_class ( MisdesignChecker ), 'too-few-public-methods' ,
368
+ is_class ('.View' ))
359
369
360
370
# Admin
361
371
# Too many public methods (40+/20)
0 commit comments