Skip to content

Commit

Permalink
fix ImportFromModule is unhashable issue (#3362)
Browse files Browse the repository at this point in the history
* ImportFromModule is unhashable
This fix makes the conversion to string prior to the deduplication to avoid this issue

* add type annotation for global_imports

* meet code formatting check

---------

Co-authored-by: zcipod <[email protected]>
Co-authored-by: Li Jiang <[email protected]>
  • Loading branch information
3 people authored and victordibia committed Aug 28, 2024
1 parent a9aac12 commit 8e9e42a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions autogen/coding/func_with_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass, field
from importlib.abc import SourceLoader
from textwrap import dedent, indent
from typing import Any, Callable, Generic, List, TypeVar, Union
from typing import Any, Callable, Generic, List, Set, TypeVar, Union

from typing_extensions import ParamSpec

Expand Down Expand Up @@ -159,12 +159,12 @@ def _build_python_functions_file(
funcs: List[Union[FunctionWithRequirements[Any, P], Callable[..., Any], FunctionWithRequirementsStr]]
) -> str:
# First collect all global imports
global_imports = set()
global_imports: Set[str] = set()
for func in funcs:
if isinstance(func, (FunctionWithRequirements, FunctionWithRequirementsStr)):
global_imports.update(func.global_imports)
global_imports.update(map(_import_to_str, func.global_imports))

content = "\n".join(map(_import_to_str, global_imports)) + "\n\n"
content = "\n".join(global_imports) + "\n\n"

for func in funcs:
content += _to_code(func) + "\n\n"
Expand Down

0 comments on commit 8e9e42a

Please sign in to comment.