Skip to content

Commit c3875cd

Browse files
arevenycarlio
authored andcommitted
Prevent a crash when transform lookups return an AssignAttr
1 parent bbce61b commit c3875cd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pylint_django/transforms/fields.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,25 @@ def apply_type_shim(cls, _context=None): # noqa
8989
# is an ImportFrom which has no qname() method, causing the checker
9090
# to die...
9191
if utils.PY3:
92-
base_nodes = [n for n in base_nodes[1] if not isinstance(n, nodes.ImportFrom)]
92+
base_nodes = [_valid_base_node(n, _context) for n in base_nodes[1]]
93+
base_nodes = [n for n in base_nodes if n]
9394
else:
9495
base_nodes = list(base_nodes[1])
9596

9697
return iter([cls] + base_nodes)
9798

9899

100+
def _valid_base_node(node, context):
101+
"""Attempts to convert `node` to a valid base node, returns None if it cannot."""
102+
if isinstance(node, nodes.AssignAttr):
103+
inferred = next(node.parent.value.infer(context), None)
104+
if inferred and isinstance(node, nodes.ClassDef):
105+
return inferred
106+
return None
107+
if isinstance(node, nodes.ImportFrom):
108+
return None
109+
return node
110+
111+
99112
def add_transforms(manager):
100113
manager.register_transform(nodes.ClassDef, inference_tip(apply_type_shim), is_model_or_form_field)

0 commit comments

Comments
 (0)