Compute a module's dependencies after parsing it. This is used when we parse a file that we didn't have up-to-date cache information for. When we have an up-to-date cache, we just use the cached info.
(self)
| 3354 | self.suppressed_set.add(dep) |
| 3355 | |
| 3356 | def compute_dependencies(self) -> None: |
| 3357 | """Compute a module's dependencies after parsing it. |
| 3358 | |
| 3359 | This is used when we parse a file that we didn't have |
| 3360 | up-to-date cache information for. When we have an up-to-date |
| 3361 | cache, we just use the cached info. |
| 3362 | """ |
| 3363 | manager = self.manager |
| 3364 | assert self.tree is not None |
| 3365 | |
| 3366 | # Compute (direct) dependencies. |
| 3367 | # Add all direct imports (this is why we needed the first pass). |
| 3368 | # Also keep track of each dependency's source line. |
| 3369 | # Missing dependencies will be moved from dependencies to |
| 3370 | # suppressed when they fail to be loaded in load_graph. |
| 3371 | |
| 3372 | self.dependencies = [] |
| 3373 | self.dependencies_set = set() |
| 3374 | self.suppressed = [] |
| 3375 | self.suppressed_set = set() |
| 3376 | self.priorities = {} # id -> priority |
| 3377 | self.dep_line_map = {} # id -> line |
| 3378 | self.dep_hashes = {} |
| 3379 | # We copy imports as defs to (partially) support some legacy mypy plugins, |
| 3380 | # most notably old NumPy plugin that does some imports patching, see #21323. |
| 3381 | copied_imports = False |
| 3382 | if not self.tree.defs and self.tree.raw_data is not None: |
| 3383 | self.tree.defs = list(self.tree.imports) |
| 3384 | copied_imports = True |
| 3385 | dep_entries = manager.all_imported_modules_in_file( |
| 3386 | self.tree |
| 3387 | ) + self.manager.plugin.get_additional_deps(self.tree) |
| 3388 | if copied_imports: |
| 3389 | self.tree.defs = [] |
| 3390 | for pri, id, line in dep_entries: |
| 3391 | self.priorities[id] = min(pri, self.priorities.get(id, PRI_ALL)) |
| 3392 | if id == self.id: |
| 3393 | continue |
| 3394 | self.add_dependency(id) |
| 3395 | if id not in self.dep_line_map: |
| 3396 | self.dep_line_map[id] = line |
| 3397 | import_lines = self.dep_line_map.values() |
| 3398 | self.imports_ignored = { |
| 3399 | line: codes for line, codes in self.tree.ignored_lines.items() if line in import_lines |
| 3400 | } |
| 3401 | # Every module implicitly depends on builtins. |
| 3402 | if self.id != "builtins": |
| 3403 | self.add_dependency("builtins") |
| 3404 | if self.tree.uses_template_strings: |
| 3405 | self.add_dependency("string.templatelib") |
| 3406 | |
| 3407 | self.check_blockers() # Can fail due to bogus relative imports |
| 3408 | |
| 3409 | def type_check_first_pass(self, recurse_into_functions: bool = True) -> None: |
| 3410 | if self.options.semantic_analysis_only: |
no test coverage detected