Skip to content

Flow control statements inside 'with' statement #98

pyjsorg opened this Issue Apr 27, 2012 · 0 comments

1 participant

pyjsorg commented Apr 27, 2012

'return', 'break', 'continue' and possibly some other statements need some workaround to get them working properly inside with:

x = 0
for i in range(10):
    x += 1
    with self.Dummy():
    x += 100

This code has to call contextmanager.exit() before doing 'continue'.

Walk 'with' body AST and replace control statements with 'raise WithFlowStatement(statementtype)', which would be caught by 'with', and statement would be issued after finalizing context-manager.
Problem: we cannot simply add "if (statement=='continue') continue" as that would be syntax error. Translator should know whether it is inside loop/func or not.

Original issue: (July 01, 2011 06:52:00)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.