# Buggy code
def enable(self, app=None):
    """Enable event loop integration with PyQt4.

    Parameters
    ----------
    app : Qt Application, optional.
        Running application to use.  If not given, we probe Qt for an
        existing application object, and create a new one if none is found.

    Notes
    -----
    This methods sets the PyOS_InputHook for PyQt4, which allows
    the PyQt4 to integrate with terminal based applications like
    IPython.

    If ``app`` is not given we probe for an existing one, and return it if
    found.  If no existing app is found, we create an :class:`QApplication`
    as follows::

        from PyQt4 import QtCore
        app = QtGui.QApplication(sys.argv)
    """
    from IPython.lib.inputhookqt4 import create_inputhook_qt4
    from IPython.external.appnope import nope

    app, inputhook_qt4 = create_inputhook_qt4(self, app)
    self.manager.set_inputhook(inputhook_qt4)
    nope()

    return app


# Traceback (AttributeError)
In [4]: Traceback (most recent call last):
File "/Users/ehvatum/Desktop/ipython_git/IPython/lib/inputhookqt4.py", line 123, in inputhook_qt4
event_loop.exec_()
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "_ctypes/callbacks.c", line 277, in 'calling callback function'
File "/Users/ehvatum/Desktop/ipython_git/IPython/lib/inputhookqt4.py", line 130, in inputhook_qt4
mgr.clear_inputhook()
AttributeError: 'Qt4InputHook' object has no attribute 'clear_inputhook'

If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True

Traceback (most recent call last):
File "/usr/local/bin/ipython", line 9, in
load_entry_point('ipython==3.0.0-dev', 'console_scripts', 'ipython')()
File "/Users/ehvatum/Desktop/ipython_git/IPython/init.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Users/ehvatum/Desktop/ipython_git/IPython/config/application.py", line 549, in launch_instance
app.start()
File "/Users/ehvatum/Desktop/ipython_git/IPython/terminal/ipapp.py", line 372, in start
self.shell.mainloop()
File "/Users/ehvatum/Desktop/ipython_git/IPython/terminal/interactiveshell.py", line 383, in mainloop
self.interact(display_banner=display_banner)
File "/Users/ehvatum/Desktop/ipython_git/IPython/terminal/interactiveshell.py", line 446, in interact
self.hooks.pre_prompt_hook()
File "/Users/ehvatum/Desktop/ipython_git/IPython/core/hooks.py", line 137, in call
return cmd(*args, **kw)
File "/Users/ehvatum/Desktop/ipython_git/IPython/lib/inputhookqt4.py", line 174, in preprompthook_qt4
mgr.set_inputhook(inputhook_qt4)
AttributeError: 'Qt4InputHook' object has no attribute 'set_inputhook'

If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True

# Fixed code
def enable(self, app=None):
    """Enable event loop integration with PyQt4.

    Parameters
    ----------
    app : Qt Application, optional.
        Running application to use.  If not given, we probe Qt for an
        existing application object, and create a new one if none is found.

    Notes
    -----
    This methods sets the PyOS_InputHook for PyQt4, which allows
    the PyQt4 to integrate with terminal based applications like
    IPython.

    If ``app`` is not given we probe for an existing one, and return it if
    found.  If no existing app is found, we create an :class:`QApplication`
    as follows::

        from PyQt4 import QtCore
        app = QtGui.QApplication(sys.argv)
    """
    from IPython.lib.inputhookqt4 import create_inputhook_qt4
    from IPython.external.appnope import nope

    app, inputhook_qt4 = create_inputhook_qt4(self.manager, app)
    self.manager.set_inputhook(inputhook_qt4)
    nope()

    return app