alexmojaki / alexmojaki/birdseye

"too many statically nested blocks" error in long elif chain

Aperta
#16 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
JavaScript
Stelle
1.7k
Fork
73
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

MCVE:

```python
from birdseye import eye

@eye
def foo():
if 0:
pass
elif 0:
pass
elif 1:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
elif 0:
pass
```

The reason this happens is that:

> [elif clauses don’t have a special representation in the AST, but rather appear as extra If nodes within the orelse section of the previous one.](https://greentreesnakes.readthedocs.io/en/latest/nodes.html#If)

which leads to many hidden nested `with` blocks created when transforming the AST to trace statements.

It should be possible to fix this by only wrapping the body of each elif/else block in a with statement.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.