[Bug] method_logger uses fragile definition-time inspect stack frame instead of func.__qualname__
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
Inizia leggendo method_logger() in mesa/mesa_logging.py e verifica come il suo wrapper costruisce il messaggio di log. Aggiorna il nome qualificato al momento della chiamata del metodo, come descritto nell’issue, poi esegui o aggiungi un test mirato per un metodo di classe decorato per confermare che l’output includa SampleAgent.step.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
In mesa/mesa_logging.py, method_logger() attempts to capture the class name of a decorated method using inspect.getouterframes(inspect.currentframe())[1][3] at decorator definition time.
This has two main issues:
- Frame inspection at definition time evaluates before the class object is constructed, yielding
<module>or outer context frame names instead of the actual class name. - It is fragile to context nesting, decorator composition, or outer wrapper functions.
Expected behavior
method_logger() should dynamically capture and display the qualified class and method name (e.g., SampleAgent.step) when the decorated method is executed.
To Reproduce
from mesa.mesa_logging import method_logger
class SampleAgent:
@method_logger("mesa")
def step(self):
pass
agent = SampleAgent()
agent.step()
# Expected log output format: calling SampleAgent.step with ...
# Actual behavior: inspect evaluates frame at definition time yielding <module>
Proposed Fix
Leverage Python's standard func.qualname inside the wrapper function execution rather than static stack frames at definition time:
def method_logger(name: str):
logger = get_module_logger(name)
def real_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
qualname = func.__qualname__
logger.debug(
f"calling {qualname} with {args[1:]} and {kwargs}"
)
res = func(*args, **kwargs)
return res
return wrapper
return real_decorator
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? 🙋♂️
- Lingua principale
- Python
- Stelle
- 3.9k
- Fork
- 1.4k
- Merge medio
- 4g 8h
- PR unite (30g)
- 44
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mesa/mesa
-
DataRecorder skips an in-window final snapshot after auto-disablingForse già presa @atul-upadhyay-7 l’ha presa 5 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug performance
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
SpaceRenderer.canvas raises KeyError with Altair backend when a property layer is setForse già presa @AshNicolus l’ha presa 23 giorni fa. Apertabug docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Error when running Hotelling's Law exampleForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
mesa/mesa#2824 · 13 commenti ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
FAIRmat-NFDI/pynxtools#861 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NVIDIA/nsight-python#88 ·
I maintainer di solito rispondono entro 1 giorno
-
Criteria can pass when the deliverable is missingForse già presa @clementtisseau l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
harveyai/harvey-labs#217 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
databrickslabs/ontos#1420 ·
I maintainer di solito rispondono entro 3 giorni