Skip to content

Commit 9d410f3

Browse files
authored
Merge pull request #7341 from jepler/fix-stubs-import-nothing
only import a module if we use something from it
2 parents 5b9fefe + 41beca1 commit 9d410f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/extract_pyi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ def convert_folder(top_level, stub_directory):
228228
imports, type_imports = extract_imports(tree)
229229
import_lines = ["from __future__ import annotations"]
230230
for type_module, used_types in type_imports.items():
231-
import_lines.append(f"from {type_module} import {', '.join(sorted(used_types))}")
231+
if used_types:
232+
import_lines.append(f"from {type_module} import {', '.join(sorted(used_types))}")
232233
import_lines.extend(f"import {m}" for m in sorted(imports))
233234
import_body = "\n".join(import_lines)
234235
m = re.match(r'(\s*""".*?""")', stub_contents, flags=re.DOTALL)

0 commit comments

Comments
 (0)