From 7850c8d799b31d62a2d3f419e54e53a862ba2321 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Thu, 8 May 2025 17:08:47 -0700 Subject: [PATCH] Lint --- libs/langgraph/langgraph/func/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index de0e25648..72bc42bd2 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -45,12 +45,21 @@ class TaskFunction(Generic[P, T]): cache_policy: Optional[CachePolicy[Callable[P, Union[str, bytes]]]] = None, name: Optional[str] = None, ) -> None: + if name is not None: + if hasattr(func, "__func__"): + # handle class methods + # NOTE: we're modifying the instance method to avoid modifying + # the original class method in case it's shared across multiple tasks + instance_method = functools.partial(func.__func__, func.__self__) # type: ignore [union-attr] + instance_method.__name__ = name # type: ignore [attr-defined] + func = instance_method + else: + # handle regular functions / partials / callable classes, etc. + func.__name__ = name self.func = func self.retry = retry self.cache_policy = cache_policy functools.update_wrapper(self, func) - if name is not None: - setattr(self, "__name__", name) def __call__(self, *args: P.args, **kwargs: P.kwargs) -> SyncAsyncFuture[T]: return call(