Mein Wrapper -Dekorateur, der eine abstrakte Methode umhülltPython

Python-Programme
Guest
 Mein Wrapper -Dekorateur, der eine abstrakte Methode umhüllt

Post by Guest »

Ich erstelle einen Dekorateur, um Protokoll/Ergebnisse zu speichern. Dies wird jedoch in die abstrakte Klasse eingeführt:
from functools import wraps

load_dotenv()

class Evaluator(ABC):
def __init__(self, evaluation_config, framework_config, **kwargs):

self.evaluation_config = evaluation_config
self.framework_config = framework_config

self.logger = WandbLogger()

@abstractmethod
def _create_metrics(self) -> List[Metric]:
pass

@abstractmethod
def load_evaluation_data(self, data_path):
pass

@staticmethod
def log_results(func):
"""Decorator to log evaluation results."""
print("this is called")
@wraps(func)
def wrapper(self, *args, **kwargs):
print("this is called too!")
result = func(*args, **kwargs)
self.logger.log(evaluation_result=result, config=self.framework_config)
return result

return wrapper

@log_results # Now correctly applied as an instance method
@abstractmethod
def __call__(self, *args, **kwargs):
pass

< /code>
Als ich renne, bemerkte ich, dass es nur gedruckt wurde: < /p>
this is called
< /code>
``
ohne den Druck zu drucken ("Dies heißt auch!") < /code> < /p>
Ich bin so verwirrt. Ich bin so verwirrt . Danke!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post