Skip to content

Commit 8625db7

Browse files
author
Guido van Rossum
committed
Fix an assert that passed type checks but could fail at runtime.
Fixes #2751. (That assert was added in #2341 to force the type checker to believe that 'file' is a MypyFile instance, but the rest of the code makes it clear that it may also be None, in which case the assert fails.)
1 parent b759293 commit 8625db7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ def visit_member_expr(self, expr: MemberExpr) -> None:
24042404
# In this case base.node is the module's MypyFile and we look up
24052405
# bar in its namespace. This must be done for all types of bar.
24062406
file = base.node
2407-
assert isinstance(file, MypyFile)
2407+
assert isinstance(file, (MypyFile, type(None)))
24082408
n = file.names.get(expr.name, None) if file is not None else None
24092409
if n:
24102410
n = self.normalize_type_alias(n, expr)

0 commit comments

Comments
 (0)