Skip to content

Commit

Permalink
Use union instead of pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Jan 22, 2025
1 parent 096bde7 commit b2c8abd
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions autogen/coding/func_with_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
from __future__ import annotations

import functools
import importlib
Expand All @@ -20,7 +19,7 @@
P = ParamSpec("P")


def _to_code(func: FunctionWithRequirements[T, P] | Callable[P, T] | FunctionWithRequirementsStr) -> str:
def _to_code(func: Union["FunctionWithRequirements[T, P]", Callable[P, T], "FunctionWithRequirementsStr"]) -> str:
if isinstance(func, FunctionWithRequirementsStr):
return func.func

Expand All @@ -40,7 +39,7 @@ class Alias:
@dataclass
class ImportFromModule:
module: str
imports: list[str | Alias]
imports: list[Union[str, Alias]]


Import = Union[str, ImportFromModule, Alias]
Expand All @@ -53,7 +52,7 @@ def _import_to_str(im: Import) -> str:
return f"import {im.name} as {im.alias}"
else:

def to_str(i: str | Alias) -> str:
def to_str(i: Union[str, Alias]) -> str:
if isinstance(i, str):
return i
else:
Expand Down Expand Up @@ -123,7 +122,7 @@ class FunctionWithRequirements(Generic[T, P]):
@classmethod
def from_callable(
cls, func: Callable[P, T], python_packages: list[str] = [], global_imports: list[Import] = []
) -> FunctionWithRequirements[T, P]:
) -> "FunctionWithRequirements[T, P]":
return cls(python_packages=python_packages, global_imports=global_imports, func=func)

@staticmethod
Expand Down Expand Up @@ -162,7 +161,7 @@ def wrapper(func: Callable[P, T]) -> FunctionWithRequirements[T, P]:


def _build_python_functions_file(
funcs: list[FunctionWithRequirements[Any, P] | Callable[..., Any] | FunctionWithRequirementsStr],
funcs: list[Union[FunctionWithRequirements[Any, P], Callable[..., Any], FunctionWithRequirementsStr]],
) -> str:
# First collect all global imports
global_imports: set[str] = set()
Expand All @@ -178,7 +177,7 @@ def _build_python_functions_file(
return content


def to_stub(func: Callable[..., Any] | FunctionWithRequirementsStr) -> str:
def to_stub(func: Union[Callable[..., Any], FunctionWithRequirementsStr]) -> str:
"""Generate a stub for a function as a string
Args:
Expand Down

0 comments on commit b2c8abd

Please sign in to comment.