Skip to content

Commit 8cfe16b

Browse files
author
Guido van Rossum
committed
Do deferred (second) type checker pass after all first passes in an SCC.
1 parent eba78d9 commit 8cfe16b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

mypy/build.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,25 +1409,29 @@ def semantic_analysis_pass_three(self) -> None:
14091409
if self.options.dump_type_stats:
14101410
dump_type_stats(self.tree, self.xpath)
14111411

1412-
def type_check(self) -> None:
1412+
def type_check_first_pass(self) -> None:
14131413
manager = self.manager
14141414
if self.options.semantic_analysis_only:
14151415
return
14161416
with self.wrap_context():
1417-
type_checker = TypeChecker(manager.errors, manager.modules, self.options,
1418-
self.tree, self.xpath)
1419-
type_checker.check_first_pass()
1420-
type_checker.check_second_pass()
1421-
manager.all_types.update(type_checker.type_map)
1417+
self.type_checker = TypeChecker(manager.errors, manager.modules, self.options,
1418+
self.tree, self.xpath)
1419+
self.type_checker.check_first_pass()
1420+
1421+
def type_check_second_pass(self) -> None:
1422+
manager = self.manager
1423+
with self.wrap_context():
1424+
self.type_checker.check_second_pass()
1425+
manager.all_types.update(self.type_checker.type_map)
14221426

14231427
if self.options.incremental:
1424-
self._patch_indirect_dependencies(type_checker.module_refs,
1425-
type_checker.type_map)
1428+
self._patch_indirect_dependencies(self.type_checker.module_refs,
1429+
self.type_checker.type_map)
14261430

14271431
if self.options.dump_inference_stats:
14281432
dump_type_stats(self.tree, self.xpath, inferred=True,
1429-
typemap=type_checker.type_map)
1430-
manager.report_file(self.tree, type_checker.type_map)
1433+
typemap=self.type_checker.type_map)
1434+
manager.report_file(self.tree, self.type_checker.type_map)
14311435

14321436
def _patch_indirect_dependencies(self,
14331437
module_refs: Set[str],
@@ -1736,7 +1740,10 @@ def process_stale_scc(graph: Graph, scc: List[str]) -> None:
17361740
for id in scc:
17371741
graph[id].semantic_analysis_pass_three()
17381742
for id in scc:
1739-
graph[id].type_check()
1743+
graph[id].type_check_first_pass()
1744+
for id in scc:
1745+
graph[id].type_check_second_pass()
1746+
for id in scc:
17401747
graph[id].write_cache()
17411748
graph[id].mark_as_rechecked()
17421749

0 commit comments

Comments
 (0)