From ddc0e4be5825d0c9c9e8b6aa7083f91619187422 2008-03-16 06:46:23 From: Ville M. Vainio Date: 2008-03-16 06:46:23 Subject: [PATCH] _ip.runlines() handles cleanup of scripts that start new else blocks on indent level 0 correctly --- diff --git a/IPython/ipapi.py b/IPython/ipapi.py index 99f2fc1..307fe8c 100644 --- a/IPython/ipapi.py +++ b/IPython/ipapi.py @@ -275,11 +275,12 @@ class IPApi: lines = script.splitlines() level = 0 for l in lines: - stripped = l.lstrip() - if not l.strip(): + lstripped = l.lstrip() + stripped = l.strip() + if not stripped: continue - newlevel = len(l) - len(stripped) - if level > 0 and newlevel == 0: + newlevel = len(l) - len(lstripped) + if level > 0 and newlevel == 0 and not stripped.endswith(':'): # add empty line res.append('') res.append(l)