mesa
mesa copied to clipboard
[Bug] method_logger uses fragile definition-time inspect stack frame instead of func.__qualname__
Updated Minimal Reproducer
While a direct @method_logger("mesa") inside a top-level class body resolves the immediate class frame, inspect.getouterframes(inspect.currentframe())[1][3] fails whenever method_logger is invoked via a custom wrapper decorator, applied dynamically outside the class body, or used on nested classes:
from mesa.mesa_logging import method_logger
# 1. Custom wrapper / shorthand decorator factory
def mesa_step_logger(func):
return method_logger("mesa")(func)
class SampleAgent:
@mesa_step_logger
def step(self):
pass
# 2. Nested class
class SubComponent:
@method_logger("mesa")
def update(self):
pass
# 3. Post-definition / dynamic decoration
class DynamicAgent:
def step(self):
pass
DynamicAgent.step = method_logger("mesa")(DynamicAgent.step)
Additional context I am a first-time contributor and would love to open a Pull Request to fix this! Could you please assign this issue to me? 🙋♂️
Updated the issue description above with a minimal reproducer covering wrapper decorator factories, nested classes, and post-definition decoration.