Skip to content

Commit b8f1592

Browse files
authored
Don't crash when inspecting classes loaded from cache (#2185)
`ClassDef`s are populated with faked `TypeInfo` when loaded from cache. A faked `TypeInfo` doesn't have all attributes of a `TypeInfo` set. So we'll avoid inspecting the faked `TypeInfo`
1 parent 95e7d4d commit b8f1592

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mypy_django_plugin/transformers/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
CallExpr,
1515
Context,
1616
Expression,
17+
FakeInfo,
1718
NameExpr,
1819
RefExpr,
1920
Statement,
@@ -640,6 +641,10 @@ def statements(self) -> Iterable[Statement]:
640641
while model_bases:
641642
model = model_bases.popleft()
642643
yield from model.defs.body
644+
if isinstance(model.info, FakeInfo):
645+
# While loading from cache ClassDef infos are faked and 'FakeInfo' doesn't have
646+
# all attributes of a 'TypeInfo' set. See #2184
647+
continue
643648
for base in model.info.bases:
644649
# Only produce any additional statements from abstract model bases, as they
645650
# simulate regular python inheritance. Avoid concrete models, and any of their

0 commit comments

Comments
 (0)