Code object comparison could lead to monitoring issue
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
Currently we compare code objects with a lot of its features, but not the file it is defined in - that might make some sense because the two code objects are "equivalent" as long as all their features match. However, the two code objects could still be two different ones - for example, if they are two exact same functions defined in two different files (this is a real case for me and it took me a while to figure it out).
The problem is, code objects can be used as keys. When we have "equal but not the same" code objects, it could affect monitoring. We thought we were monitoring one code object while we are actually monitoring another one.
The code was like this:
@cache
def get_code_lineno(code):
...
return {code: [...]}
assert code1 == code2 # two code objects in two different files
for c, linenos in get_code_lineno(code1):
sys.monitoring.set_local_events(tool, c, E.LINE)
for c, linenos in get_code_lineno(code2):
# This does not instrument code2! This instruments code1 because of the cache!
sys.monitoring.set_local_events(tool, c, E.LINE)
Do we consider this an expected behavior? Should we just "live with it" as it's not that common? (Again, this is a real issue I had when I was working on a project).
@markshannon
CPython versions tested on:
3.12, CPython main branch, 3.13, 3.14
Operating systems tested on:
No response
Guida per i contributori
Apri 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.
Direzione di ricerca
Il report non indica alcun file sorgente né alcun test. Inizia riproducendo la ricerca nella cache con oggetti codice equivalenti provenienti da file diversi, quindi esamina il confronto tra oggetti codice e il punto di ingresso sys.monitoring.set_local_events. Il comportamento previsto deve essere deciso prima che un test di regressione possa verificare che il monitoraggio non punti all’oggetto codice errato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 30/100