Skip to content
This repository

"import braces" crashes ipython #843

Closed
Pasotaman opened this Issue October 07, 2011 · 1 comment

2 participants

Pasotaman Fernando Perez
Pasotaman

Trying to trigger the well-known easter egg "not a chance" with "from __future__ import braces" results in IPython 0.11 crashing as detailed in the crash log below. I realize this is not a very serious bug but I still thought it might be interesting for the developers.

IPython post-mortem report

{'commit_hash': '464280a',
 'commit_source': 'archive substitution',
 'ipython_path': '/usr/lib/python2.7/dist-packages/IPython',
 'ipython_version': '0.11',
 'os_name': 'posix',
 'platform': 'Linux-3.0.0-1-amd64-x86_64-with-debian-wheezy-sid',
 'sys_executable': '/usr/bin/python',
 'sys_platform': 'linux2',
 'sys_version': '2.7.2+ (default, Oct  5 2011, 10:41:47) \n[GCC 4.6.1]'}

***************************************************************************



***************************************************************************

Crash traceback:

---------------------------------------------------------------------------
SyntaxError                                  Python 2.7.2+: /usr/bin/python
                                                   Fri Oct  7 19:02:37 2011
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
/usr/bin/ipython in <module>()
      1 #!/usr/bin/env python
      2 """Terminal-based IPython entry point.
      3 """
      4 
      5 from IPython.frontend.terminal.ipapp import launch_new_instance
      6 
      7 try:
----> 8   launch_new_instance()
        global launch_new_instance = <function launch_new_instance at 0x160fe60>
      9 except ImportError as e:
     10   if "qt.console.qtconsoleapp" in e.message:
     11     print "Could not start qtconsole. Please install ipython-qtconsole"

/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.pyc in launch_new_instance()
    355         ipython_dir = get_ipython_dir()
    356     profile_dir = os.path.join(ipython_dir, 'profile_default')
    357     cl = PyFileConfigLoader(default_config_file_name, profile_dir)
    358     try:
    359         config = cl.load_config()
    360     except IOError:
    361         # no config found
    362         config = Config()
    363     return config
    364 
    365 
    366 def launch_new_instance():
    367     """Create and run a full blown IPython instance"""
    368     app = TerminalIPythonApp.instance()
    369     app.initialize()
--> 370     app.start()
    371 
    372 
    373 if __name__ == '__main__':
    374     launch_new_instance()

/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.pyc in start(self=<IPython.frontend.terminal.ipapp.TerminalIPythonApp object>)
    329         if gui or self.pylab:
    330             try:
    331                 self.log.info("Enabling GUI event loop integration, "
    332                               "toolkit=%s, pylab=%s" % (gui, self.pylab) )
    333                 activate(gui)
    334             except:
    335                 self.log.warn("Error in enabling GUI event loop integration:")
    336                 self.shell.showtraceback()
    337 
    338     def start(self):
    339         if self.subapp is not None:
    340             return self.subapp.start()
    341         # perform any prexec steps:
    342         if self.interact:
    343             self.log.debug("Starting IPython's mainloop...")
--> 344             self.shell.mainloop()
    345         else:
    346             self.log.debug("IPython not interactive...")
    347 
    348 
    349 def load_default_config(ipython_dir=None):
    350     """Load the default config file from the default ipython_dir.
    351 
    352     This is useful for embedded shells.
    353     """
    354     if ipython_dir is None:
    355         ipython_dir = get_ipython_dir()
    356     profile_dir = os.path.join(ipython_dir, 'profile_default')
    357     cl = PyFileConfigLoader(default_config_file_name, profile_dir)
    358     try:
    359         config = cl.load_config()

/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.pyc in mainloop(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=None)
    207     #-------------------------------------------------------------------------
    208     # Mainloop and code execution logic
    209     #-------------------------------------------------------------------------
    210 
    211     def mainloop(self, display_banner=None):
    212         """Start the mainloop.
    213 
    214         If an optional banner argument is given, it will override the
    215         internally created default banner.
    216         """
    217         
    218         with nested(self.builtin_trap, self.display_trap):
    219 
    220             while 1:
    221                 try:
--> 222                     self.interact(display_banner=display_banner)
        global See = undefined
        global also = undefined
    223                     #self.interact_with_readline()                
    224                     # XXX for testing of a readline-decoupled repl loop, call
    225                     # interact_with_readline above
    226                     break
    227                 except KeyboardInterrupt:
    228                     # this should not be necessary, but KeyboardInterrupt
    229                     # handling seems rather unpredictable...
    230                     self.write("\nKeyboardInterrupt in interact()\n")
    231 
    232     def interact(self, display_banner=None):
    233         """Closely emulate the interactive Python console."""
    234 
    235         # batch run -> do not interact        
    236         if self.exit_now:
    237             return

/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.pyc in interact(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=False)
    297                      'Because of how pdb handles the stack, it is impossible\n'
    298                      'for IPython to properly format this particular exception.\n'
    299                      'IPython will resume normal operation.')
    300             except:
    301                 # exceptions here are VERY RARE, but they can be triggered
    302                 # asynchronously by signal handlers, for example.
    303                 self.showtraceback()
    304             else:
    305                 self.input_splitter.push(line)
    306                 more = self.input_splitter.push_accepts_more()
    307                 if (self.SyntaxTB.last_syntax_error and
    308                     self.autoedit_syntax):
    309                     self.edit_syntax_error()
    310                 if not more:
    311                     source_raw = self.input_splitter.source_raw_reset()[1]
--> 312                     self.run_cell(source_raw)
    313                 
    314         # We are off again...
    315         __builtin__.__dict__['__IPYTHON__active'] -= 1
    316 
    317         # Turn off the exit flag, so the mainloop can be restarted if desired
    318         self.exit_now = False
    319 
    320     def raw_input(self, prompt=''):
    321         """Write a prompt and read a line.
    322 
    323         The returned line does not include the trailing newline.
    324         When the user enters the EOF key sequence, EOFError is raised.
    325 
    326         Optional inputs:
    327 

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_cell(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, raw_cell=u'from __future__ import braces\n', store_history=True)
   2282             
   2283                 with self.display_trap:
   2284                     try:
   2285                         code_ast = ast.parse(cell, filename=cell_name)
   2286                     except IndentationError:
   2287                         self.showindentationerror()
   2288                         self.execution_count += 1
   2289                         return None
   2290                     except (OverflowError, SyntaxError, ValueError, TypeError,
   2291                             MemoryError):
   2292                         self.showsyntaxerror()
   2293                         self.execution_count += 1
   2294                         return None
   2295             
   2296                     self.run_ast_nodes(code_ast.body, cell_name,
-> 2297                                                         interactivity="last_expr")
   2298             
   2299                     # Execute any registered post-execution functions.
   2300                     for func, status in self._post_execute.iteritems():
   2301                         if not status:
   2302                             continue
   2303                         try:
   2304                             func()
   2305                         except:
   2306                             self.showtraceback()
   2307                             # Deactivate failing function
   2308                             self._post_execute[func] = False
   2309                 
   2310         if store_history:
   2311             # Write output to the database. Does nothing unless
   2312             # history output logging is enabled.

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_ast_nodes(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, nodelist=[<_ast.ImportFrom object>], cell_name='<ipython-input-1-2aebb3fc8ecf>', interactivity='none')
   2342                 interactivity = "none"
   2343         
   2344         if interactivity == 'none':
   2345             to_run_exec, to_run_interactive = nodelist, []
   2346         elif interactivity == 'last':
   2347             to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
   2348         elif interactivity == 'all':
   2349             to_run_exec, to_run_interactive = [], nodelist
   2350         else:
   2351             raise ValueError("Interactivity was %r" % interactivity)
   2352             
   2353         exec_count = self.execution_count
   2354         
   2355         for i, node in enumerate(to_run_exec):
   2356             mod = ast.Module([node])
-> 2357             code = self.compile(mod, cell_name, "exec")
   2358             if self.run_code(code):
   2359                 return True
   2360 
   2361         for i, node in enumerate(to_run_interactive):
   2362             mod = ast.Interactive([node])
   2363             code = self.compile(mod, cell_name, "single")
   2364             if self.run_code(code):
   2365                 return True
   2366 
   2367         return False
   2368     
   2369     def run_code(self, code_obj):
   2370         """Execute a code object.
   2371 
   2372         When an exception occurs, self.showtraceback() is called to display a

/usr/lib/python2.7/codeop.pyc in __call__(self=<IPython.core.compilerop.CachingCompiler instance>, source=<_ast.Module object>, filename='<ipython-input-1-2aebb3fc8ecf>', symbol='exec')
    118     - Raise SyntaxError, ValueError or OverflowError if the command is a
    119       syntax error (OverflowError and ValueError can be produced by
    120       malformed literals).
    121     """
    122     return _maybe_compile(_compile, source, filename, symbol)
    123 
    124 class Compile:
    125     """Instances of this class behave much like the built-in compile
    126     function, but if one is used to compile text containing a future
    127     statement, it "remembers" and compiles all subsequent program texts
    128     with the statement in force."""
    129     def __init__(self):
    130         self.flags = PyCF_DONT_IMPLY_DEDENT
    131 
    132     def __call__(self, source, filename, symbol):
--> 133         codeob = compile(source, filename, symbol, self.flags, 1)
    134         for feature in _features:
    135             if codeob.co_flags & feature.compiler_flag:
    136                 self.flags |= feature.compiler_flag
    137         return codeob
    138 
    139 class CommandCompiler:
    140     """Instances of this class have __call__ methods identical in
    141     signature to compile_command; the difference is that if the
    142     instance compiles program text containing a __future__ statement,
    143     the instance 'remembers' and compiles all subsequent program texts
    144     with the statement in force."""
    145 
    146     def __init__(self,):
    147         self.compiler = Compile()
    148 

SyntaxError: not a chance (<ipython-input-1-2aebb3fc8ecf>, line 1)

***************************************************************************

History of session input:from __future__ import braces
*** Last line of input (may not be in above history):
from __future__ import braces
Fernando Perez
Owner

Thanks for your report! I can confirm the problem existed on 0.11, but fortunately it's already fixed on trunk, so you can either update to running from git master, or wait for the 0.12 release:

IPython 0.12.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from __future__ import  braces
SyntaxError: not a chance (, line 1)
Fernando Perez fperez closed this October 07, 2011
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.