From c4f7eaf2599c5709260d660d48e810aae7a8c124 Mon Sep 17 00:00:00 2001 From: Piotr Mardziel Date: Mon, 9 Dec 2024 08:51:12 -0800 Subject: [PATCH] Add missing @functools.wraps when wrapping functions and preserve wrapped class name in @CrewBase. (#1560) * Update annotations.py * Update utils.py * Update crew_base.py * Update utils.py * Update crew_base.py --------- Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com> --- src/crewai/project/annotations.py | 2 ++ src/crewai/project/crew_base.py | 4 ++++ src/crewai/project/utils.py | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/crewai/project/annotations.py b/src/crewai/project/annotations.py index be4710b2b..bf0051c4d 100644 --- a/src/crewai/project/annotations.py +++ b/src/crewai/project/annotations.py @@ -66,6 +66,8 @@ def cache_handler(func): def crew(func) -> Callable[..., Crew]: + + @wraps(func) def wrapper(self, *args, **kwargs) -> Crew: instantiated_tasks = [] instantiated_agents = [] diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py index e93452a6e..0b43882f2 100644 --- a/src/crewai/project/crew_base.py +++ b/src/crewai/project/crew_base.py @@ -213,4 +213,8 @@ def CrewBase(cls: T) -> T: callback_functions[callback]() for callback in callbacks ] + # Include base class (qual)name in the wrapper class (qual)name. + WrappedClass.__name__ = CrewBase.__name__ + "(" + cls.__name__ + ")" + WrappedClass.__qualname__ = CrewBase.__qualname__ + "(" + cls.__name__ + ")" + return cast(T, WrappedClass) diff --git a/src/crewai/project/utils.py b/src/crewai/project/utils.py index be3f757d9..2e95c755d 100644 --- a/src/crewai/project/utils.py +++ b/src/crewai/project/utils.py @@ -1,11 +1,13 @@ +from functools import wraps + def memoize(func): cache = {} + @wraps(func) def memoized_func(*args, **kwargs): key = (args, tuple(kwargs.items())) if key not in cache: cache[key] = func(*args, **kwargs) return cache[key] - memoized_func.__dict__.update(func.__dict__) return memoized_func