Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: avoid empty module set when inspecting the type annotations #220

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aiida_workgraph/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ def add_imports(type_hint):
else:
return # If no module or origin, we can't import it, e.g., for literals

if module_name not in imports:
imports[module_name] = set()
if type_name is not None:
if module_name not in imports:
imports[module_name] = set()
imports[module_name].add(type_name)

for _, type_hint in type_hints.items():
Expand Down
9 changes: 9 additions & 0 deletions tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,22 @@ def generate_structures(
) -> list[Atoms]:
pass

def generate_structures_2(
structure1: Atoms,
strain_lst1: list = None,
data1: str = "",
) -> list[Atoms]:
pass

modules = get_required_imports(generate_structures)
assert modules == {
"ase.atoms": {"Atoms"},
"typing": {"List"},
"builtins": {"list"},
"numpy": {"array"},
}
modules = get_required_imports(generate_structures_2)
assert modules == {"ase.atoms": {"Atoms"}, "builtins": {"list", "str"}}


def test_PythonJob_outputs(fixture_localhost):
Expand Down
Loading