Code snippets failing on the interpreter

Bug #266993 reported by Gael Varoquaux
4
Affects Status Importance Assigned to Milestone
IPython
Fix Released
Medium
Brian Granger

Bug Description

In [1]: from IPython.kernel.core.interpreter import Interpreter

In [2]: i = Interpreter()

In [3]: i.execute('from textwrap import dedent')
Out[3]:
{'input': {'raw': 'from textwrap import dedent',
           'translated': 'from textwrap import dedent'},
 'number': 1}

In [4]: i.execute('dedent("""a\nb""")\n')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/home/gvaroquaux/<ipython console> in <module>()

/home/gvaroquaux/dev/ipython/ipython-frontend/IPython/kernel/core/interpreter.pyc in execute_block(self, code)
    373 outflag = 1 # start by assuming error, success will reset it
    374 try:
--> 375 exec code in self.user_ns
    376 outflag = 0
    377 except SystemExit:

TypeError: exec: arg 1 must be a string, file, or code object

In [5]: i.execute('dedent(""" a\n b\n c""")\n')
---------------------------------------------------------------------------
IndentationError Traceback (most recent call last)

/home/gvaroquaux/<ipython console> in <module>()

/home/gvaroquaux/dev/ipython/ipython-frontend/IPython/kernel/core/interpreter.pyc in execute_python(self, python)
    352 for cmd in commands:
    353 try:
--> 354 code = self.command_compiler(cmd, self.filename, 'single')
    355 except (SyntaxError, OverflowError, ValueError), e:
    356 self.traceback_trap.args = sys.exc_info()

/usr/lib/python2.5/codeop.pyc in __call__(self, source, filename, symbol)
    164 - Raise SyntaxError, ValueError or OverflowError if the command is a
    165 syntax error (OverflowError and ValueError can be produced by
    166 malformed literals).
    167 """
--> 168 return _maybe_compile(self.compiler, source, filename, symbol)

/usr/lib/python2.5/codeop.pyc in _maybe_compile(compiler, source, filename, symbol)
     97 return code
     98 if not code1 and repr(err1) == repr(err2):
---> 99 raise SyntaxError, err1
    100
    101 def _compile(source, filename, symbol):

IndentationError: unexpected indent (<string>, line 1)

Related branches

Changed in ipython:
assignee: nobody → ellisonbg
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Brian Granger (ellisonbg) wrote :

This also shows up for the even simpler commands:

str("""a\nb""")

and:

str("a\nb")

I have added tests for these cases and comments in interpreter.py about what lines of code are causing these problem. The difficulty is that some of them look to be a bug in python itself.

Revision history for this message
Brian Granger (ellisonbg) wrote :

Thanks for Gael for fixing this!

Changed in ipython:
status: Confirmed → Fix Committed
Changed in ipython:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.