Skip to content

Commit 6a8460f

Browse files
cehgvanrossum
authored andcommitted
build: bail early when verifying dependencies (#4915)
Skip creating Options for dependency when it's in modules. (Micro-optimization.)
1 parent 3fe13a1 commit 6a8460f

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

mypy/build.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,26 +1983,29 @@ def verify_dependencies(self, suppressed_only: bool = False) -> None:
19831983
if self.priorities.get(dep) != PRI_INDIRECT]
19841984
all_deps = dependencies + self.suppressed + self.ancestors
19851985
for dep in all_deps:
1986+
if dep in manager.modules:
1987+
continue
19861988
options = manager.options.clone_for_module(dep)
1987-
if dep not in manager.modules and not options.ignore_missing_imports:
1988-
line = self.dep_line_map.get(dep, 1)
1989-
try:
1990-
if dep in self.ancestors:
1991-
state, ancestor = None, self # type: (Optional[State], Optional[State])
1992-
else:
1993-
state, ancestor = self, None
1994-
# Called just for its side effects of producing diagnostics.
1995-
find_module_and_diagnose(
1996-
manager, dep, options,
1997-
caller_state=state, caller_line=line,
1998-
ancestor_for=ancestor)
1999-
except (ModuleNotFound, CompileError):
2000-
# Swallow up any ModuleNotFounds or CompilerErrors while generating
2001-
# a diagnostic. CompileErrors may get generated in
2002-
# fine-grained mode when an __init__.py is deleted, if a module
2003-
# that was in that package has targets reprocessed before
2004-
# it is renamed.
2005-
pass
1989+
if options.ignore_missing_imports:
1990+
continue
1991+
line = self.dep_line_map.get(dep, 1)
1992+
try:
1993+
if dep in self.ancestors:
1994+
state, ancestor = None, self # type: (Optional[State], Optional[State])
1995+
else:
1996+
state, ancestor = self, None
1997+
# Called just for its side effects of producing diagnostics.
1998+
find_module_and_diagnose(
1999+
manager, dep, options,
2000+
caller_state=state, caller_line=line,
2001+
ancestor_for=ancestor)
2002+
except (ModuleNotFound, CompileError):
2003+
# Swallow up any ModuleNotFounds or CompilerErrors while generating
2004+
# a diagnostic. CompileErrors may get generated in
2005+
# fine-grained mode when an __init__.py is deleted, if a module
2006+
# that was in that package has targets reprocessed before
2007+
# it is renamed.
2008+
pass
20062009

20072010
def dependency_priorities(self) -> List[int]:
20082011
return [self.priorities.get(dep, PRI_HIGH) for dep in self.dependencies + self.suppressed]

0 commit comments

Comments
 (0)