only import a module if we use something from it
This prevents a bogus line such as `from types import ` from being generated. surprisingly this was not detected as a problem until a change in isort! Formerly it would remove the bad line, but now it (correctly!) errors
This commit is contained in:
parent
5b9fefe4e5
commit
41beca14af
@ -228,6 +228,7 @@ def convert_folder(top_level, stub_directory):
|
||||
imports, type_imports = extract_imports(tree)
|
||||
import_lines = ["from __future__ import annotations"]
|
||||
for type_module, used_types in type_imports.items():
|
||||
if used_types:
|
||||
import_lines.append(f"from {type_module} import {', '.join(sorted(used_types))}")
|
||||
import_lines.extend(f"import {m}" for m in sorted(imports))
|
||||
import_body = "\n".join(import_lines)
|
||||
|
Loading…
x
Reference in New Issue
Block a user