Skip to content

Commit

Permalink
Add if statement for node type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
yalef committed May 28, 2023
1 parent dbad132 commit 72235ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions flake8_django/checkers/model_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ def is_string_dunder_all(self, element):
"""
Return True if element is astroid.Const, astroid.List or astroid.Tuple and equals "__all__"
"""
if isinstance(element.value, (astroid.List, astroid.Tuple)):
assign_value = element.value
if not isinstance(
assign_value,
(astroid.List, astroid.Tuple, astroid.Const),
):
return False
if isinstance(assign_value, (astroid.List, astroid.Tuple)):
return any(
iter_item.value == '__all__'
for iter_item in element.value.itered()
for iter_item in assign_value.itered()
)
else:
node_value = element.value.value
node_value = assign_value.value
if isinstance(node_value, bytes):
node_value = node_value.decode()
return node_value == '__all__'
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/model_form_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ class Meta:

def test_method_doesnt_error(self):
pass


class ExtendedUser(User):
class Meta(User.Meta):
fields = User.Meta.fields + ('email',)
1 change: 0 additions & 1 deletion tests/fixtures/model_form_fields_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ class User5(ModelForm):
class Meta:
model = User2
fields = ['__all__']

0 comments on commit 72235ea

Please sign in to comment.