Skip to content

Commit a68bd68

Browse files
committed
Confirm the symbol table retrieved is not None
It may be None in the case of a list comprehension being declared in a class scope (not in a function of a class). This, however, is not valid python syntax.
1 parent ed9ba4f commit a68bd68

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mypy/semanal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4550,7 +4550,10 @@ def current_symbol_table(self, escape_comprehensions: bool = False) -> SymbolTab
45504550
# The caller of the comprehension is in the global space.
45514551
names = self.globals
45524552
else:
4553-
names = cast(SymbolTable, self.locals[-1 - i])
4553+
names_candidate = self.locals[-1 - i]
4554+
assert names_candidate is not None, \
4555+
"Escaping comprehension from invalid scope"
4556+
names = names_candidate
45544557
break
45554558
else:
45564559
assert False, "Should have at least one non-comprehension scope"

0 commit comments

Comments
 (0)