Skip to content

Commit 83df83d

Browse files
committed
make the new check its own method
1 parent 80b1cd9 commit 83df83d

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

mypy/semanal.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,11 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
31813181
else:
31823182
s.rvalue.accept(self)
31833183

3184-
if self.found_incomplete_ref(tag) or self.should_wait_rhs(s.rvalue, s):
3184+
if (
3185+
self.found_incomplete_ref(tag)
3186+
or self.should_wait_rhs(s.rvalue)
3187+
or self.should_wait_lhs(s)
3188+
):
31853189
# Initializer couldn't be fully analyzed. Defer the current node and give up.
31863190
# Make sure that if we skip the definition of some local names, they can't be
31873191
# added later in this scope, since an earlier definition should take precedence.
@@ -3280,7 +3284,22 @@ def analyze_identity_global_assignment(self, s: AssignmentStmt) -> bool:
32803284
node.fullname = sym.node.fullname
32813285
return True
32823286

3283-
def should_wait_rhs(self, rv: Expression, s: AssignmentStmt) -> bool:
3287+
def should_wait_lhs(self, s: AssignmentStmt) -> bool:
3288+
"""Is the l.h.s of an assignment ready?
3289+
3290+
If the eventual l.h.s. type turns out to be a special form, we need to know that before
3291+
we can process the r.h.s. properly.
3292+
"""
3293+
if self.final_iteration:
3294+
# No chance, nothing has changed.
3295+
return False
3296+
if isinstance(s.type, UnboundType):
3297+
lookup = self.lookup_qualified(s.type.name, s, suppress_errors=True)
3298+
if lookup and isinstance(lookup.node, PlaceholderNode):
3299+
return True
3300+
return False
3301+
3302+
def should_wait_rhs(self, rv: Expression) -> bool:
32843303
"""Can we already classify this r.h.s. of an assignment or should we wait?
32853304
32863305
This returns True if we don't have enough information to decide whether
@@ -3291,10 +3310,6 @@ def should_wait_rhs(self, rv: Expression, s: AssignmentStmt) -> bool:
32913310
if self.final_iteration:
32923311
# No chance, nothing has changed.
32933312
return False
3294-
if isinstance(s.type, UnboundType):
3295-
lookup = self.lookup_qualified(s.type.name, s, suppress_errors=True)
3296-
if lookup and isinstance(lookup.node, PlaceholderNode):
3297-
return True
32983313
if isinstance(rv, NameExpr):
32993314
n = self.lookup(rv.name, rv)
33003315
if n and isinstance(n.node, PlaceholderNode) and not n.node.becomes_typeinfo:
@@ -3306,11 +3321,11 @@ def should_wait_rhs(self, rv: Expression, s: AssignmentStmt) -> bool:
33063321
if n and isinstance(n.node, PlaceholderNode) and not n.node.becomes_typeinfo:
33073322
return True
33083323
elif isinstance(rv, IndexExpr) and isinstance(rv.base, RefExpr):
3309-
return self.should_wait_rhs(rv.base, s)
3324+
return self.should_wait_rhs(rv.base)
33103325
elif isinstance(rv, CallExpr) and isinstance(rv.callee, RefExpr):
33113326
# This is only relevant for builtin SCC where things like 'TypeVar'
33123327
# may be not ready.
3313-
return self.should_wait_rhs(rv.callee, s)
3328+
return self.should_wait_rhs(rv.callee)
33143329
return False
33153330

33163331
def can_be_type_alias(self, rv: Expression, allow_none: bool = False) -> bool:

0 commit comments

Comments
 (0)