mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-07-11 16:22:15 +02:00
update exp_pool decorator
This commit is contained in:
parent
4650b7bdf1
commit
6052d8b9ac
5 changed files with 173 additions and 74 deletions
|
|
@ -19,24 +19,23 @@ def check_methods(C, *methods):
|
|||
return True
|
||||
|
||||
|
||||
def get_class_name(func, *args) -> str:
|
||||
def get_class_name(func) -> str:
|
||||
"""Returns the class name of the object that a method belongs to.
|
||||
|
||||
- If `func` is a bound method, extracts the class name directly from the method.
|
||||
- If `func` is an unbound method and `args` are provided, assumes the first argument is `self` and extracts the class name.
|
||||
- Returns an empty string if neither condition is met.
|
||||
- If `func` is a bound method or a class method, extracts the class name directly from the method.
|
||||
- Returns an empty string if it's a regular function or cannot determine the class.
|
||||
"""
|
||||
if inspect.ismethod(func):
|
||||
if inspect.isclass(func.__self__):
|
||||
return func.__self__.__name__
|
||||
|
||||
return func.__self__.__class__.__name__
|
||||
|
||||
if inspect.isfunction(func) and "self" in inspect.signature(func).parameters and args:
|
||||
return args[0].__class__.__name__
|
||||
if inspect.isfunction(func):
|
||||
qualname_parts = func.__qualname__.split(".")
|
||||
if len(qualname_parts) > 1:
|
||||
class_name = qualname_parts[-2]
|
||||
if class_name.isidentifier():
|
||||
return class_name
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
def get_func_or_method_name(func, *args) -> str:
|
||||
"""Function name, or method name with class name."""
|
||||
cls_name = get_class_name(func, *args)
|
||||
|
||||
return f"{cls_name}.{func.__name__}" if cls_name else f"{func.__name__}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue