alexmojaki / alexmojaki/birdseye

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

Offen
#16 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
JavaScript
Sterne
1.7k
Forks
73
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.