From b16ba83650d5f402e645bf5c845e4be1dfd6a574 2013-05-09 21:31:16 From: Ahmet Bakan Date: 2013-05-09 21:31:16 Subject: [PATCH] Fixed a problem with evaluating indented lines in pure python code. :meth:`EmbeddedSphinxShell.process_pure_python` could not process block of code with indentation correctly. For example, the following .. ipython:: python for i in range(10): if i < 5: continue else: pass would result in two IPython lines: In [19]: for i in range(10): ....: if i < 5: ....: continue ....: In [20]: else: ....: pass ....: This would raise various types of error, indentation/snytax, etc. To resolve this problem, added a simple check for indentation in the next line which normally start a new IPython line. --- diff --git a/docs/sphinxext/ipython_directive.py b/docs/sphinxext/ipython_directive.py index 42131d1..bce5d92 100644 --- a/docs/sphinxext/ipython_directive.py +++ b/docs/sphinxext/ipython_directive.py @@ -496,6 +496,12 @@ class EmbeddedSphinxShell(object): else: # still on a multiline modified = u'%s %s' % (continuation, line) output.append(modified) + + # if the next line is indented, it should be part of multiline + if len(content) > lineno + 1: + nextline = content[lineno + 1] + if len(nextline) - len(nextline.lstrip()) > 3: + continue try: mod = ast.parse( '\n'.join(content[multiline_start:lineno+1]))