Skip to content

Commit 52a1c48

Browse files
authored
Partially support old NumPy plugin in parallel type checking (#21324)
Ref #21323 IIUC this will not fix the plugin completely unless we also call `get_additional_deps()` in the workers (which would be weird IMO). But most importantly the plugin will not crash unconditionally like now, but will infer less precise types.
1 parent b6ec270 commit 52a1c48

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

mypy/build.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,9 +3358,17 @@ def compute_dependencies(self) -> None:
33583358
self.priorities = {} # id -> priority
33593359
self.dep_line_map = {} # id -> line
33603360
self.dep_hashes = {}
3361+
# We copy imports as defs to (partially) support some legacy mypy plugins,
3362+
# most notably old NumPy plugin that does some imports patching, see #21323.
3363+
copied_imports = False
3364+
if not self.tree.defs and self.tree.raw_data is not None:
3365+
self.tree.defs = list(self.tree.imports)
3366+
copied_imports = True
33613367
dep_entries = manager.all_imported_modules_in_file(
33623368
self.tree
33633369
) + self.manager.plugin.get_additional_deps(self.tree)
3370+
if copied_imports:
3371+
self.tree.defs = []
33643372
for pri, id, line in dep_entries:
33653373
self.priorities[id] = min(pri, self.priorities.get(id, PRI_ALL))
33663374
if id == self.id:

0 commit comments

Comments
 (0)