Skip to content

Commit ae53753

Browse files
uy-rrodriguezatodorov
authored andcommitted
Corrected forms.py to fix #284
This checks for the expected `AssignName` type in `child.targets[0]` to avoid the `AttributeError`
1 parent 977b89e commit ae53753

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

pylint_django/checkers/forms.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Models."""
2-
from astroid.nodes import Assign, ClassDef
2+
from astroid.nodes import Assign, AssignName, ClassDef
33

44
from pylint.interfaces import IAstroidChecker
55
from pylint.checkers.utils import check_messages
@@ -41,14 +41,10 @@ def visit_classdef(self, node):
4141
return
4242

4343
for child in meta.get_children():
44-
if not isinstance(child, Assign):
44+
if (not isinstance(child, Assign)
45+
or not isinstance(child.targets[0], AssignName)):
4546
continue
4647

47-
# Capture and ignore AttributeError raised when targets[0] does not
48-
# have an attribute "name"
49-
try:
50-
if child.targets[0].name == 'exclude':
51-
self.add_message('W%s04' % BASE_ID, node=child)
52-
break
53-
except AttributeError:
54-
pass
48+
if child.targets[0].name == 'exclude':
49+
self.add_message('W%s04' % BASE_ID, node=child)
50+
break

0 commit comments

Comments
 (0)