Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use dict.get(key) instead of dict[key] for pure kernel

This protects against missing keys in object introspection, etc.
when using the pure Python kernel.

closes gh-516
closes gh-519
  • Loading branch information...
commit 26cd09516cc8a87218bf9b45085fb76099cdc848 1 parent a363b0b
Min RK minrk authored committed
8 IPython/core/oinspect.py
View
@@ -199,7 +199,7 @@ def call_tip(oinfo, format_call=True):
(regular functions).
"""
# Get call definition
- argspec = oinfo['argspec']
+ argspec = oinfo.get('argspec')
if argspec is None:
call_line = None
else:
@@ -218,11 +218,11 @@ def call_tip(oinfo, format_call=True):
# Now get docstring.
# The priority is: call docstring, constructor docstring, main one.
- doc = oinfo['call_docstring']
+ doc = oinfo.get('call_docstring')
if doc is None:
- doc = oinfo['init_docstring']
+ doc = oinfo.get('init_docstring')
if doc is None:
- doc = oinfo['docstring']
+ doc = oinfo.get('docstring','')
return call_line, doc
15 IPython/frontend/qt/console/frontend_widget.py
View
@@ -355,13 +355,15 @@ def _handle_object_info_reply(self, rep):
# line as string, later we can pass False to format_call and
# syntax-highlight it ourselves for nicer formatting in the
# calltip.
- if rep['content']['ismagic']:
+ content = rep['content']
+ # if this is from pykernel, 'docstring' will be the only key
+ if content.get('ismagic', False):
# Don't generate a call-tip for magics. Ideally, we should
# generate a tooltip, but not on ( like we do for actual
# callables.
call_info, doc = None, None
else:
- call_info, doc = call_tip(rep['content'], format_call=True)
+ call_info, doc = call_tip(content, format_call=True)
if call_info or doc:
self._call_tip_widget.show_call_info(call_info, doc)
@@ -369,7 +371,14 @@ def _handle_pyout(self, msg):
""" Handle display hook output.
"""
if not self._hidden and self._is_from_this_session(msg):
- self._append_plain_text(msg['content']['data']['text/plain'] + '\n')
+ data = msg['content']['data']
+ if isinstance(data, basestring):
+ # plaintext data from pure Python kernel
+ text = data
+ else:
+ # formatted output from DisplayFormatter (IPython kernel)
+ text = data.get('text/plain', '')
+ self._append_plain_text(text + '\n')
def _handle_stream(self, msg):
""" Handle stdout, stderr, and stdin.
Please sign in to comment.
Something went wrong with that request. Please try again.