Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 b5570f73b3a589dd6dc5fb92f9949aabfdaa85d9 1 parent 650cb93
Min RK authored
8 IPython/core/oinspect.py
@@ -199,7 +199,7 @@ def call_tip(oinfo, format_call=True):
199 199 (regular functions).
200 200 """
201 201 # Get call definition
202   - argspec = oinfo['argspec']
  202 + argspec = oinfo.get('argspec')
203 203 if argspec is None:
204 204 call_line = None
205 205 else:
@@ -218,11 +218,11 @@ def call_tip(oinfo, format_call=True):
218 218
219 219 # Now get docstring.
220 220 # The priority is: call docstring, constructor docstring, main one.
221   - doc = oinfo['call_docstring']
  221 + doc = oinfo.get('call_docstring')
222 222 if doc is None:
223   - doc = oinfo['init_docstring']
  223 + doc = oinfo.get('init_docstring')
224 224 if doc is None:
225   - doc = oinfo['docstring']
  225 + doc = oinfo.get('docstring','')
226 226
227 227 return call_line, doc
228 228
15 IPython/frontend/qt/console/frontend_widget.py
@@ -355,13 +355,15 @@ def _handle_object_info_reply(self, rep):
355 355 # line as string, later we can pass False to format_call and
356 356 # syntax-highlight it ourselves for nicer formatting in the
357 357 # calltip.
358   - if rep['content']['ismagic']:
  358 + content = rep['content']
  359 + # if this is from pykernel, 'docstring' will be the only key
  360 + if content.get('ismagic', False):
359 361 # Don't generate a call-tip for magics. Ideally, we should
360 362 # generate a tooltip, but not on ( like we do for actual
361 363 # callables.
362 364 call_info, doc = None, None
363 365 else:
364   - call_info, doc = call_tip(rep['content'], format_call=True)
  366 + call_info, doc = call_tip(content, format_call=True)
365 367 if call_info or doc:
366 368 self._call_tip_widget.show_call_info(call_info, doc)
367 369
@@ -369,7 +371,14 @@ def _handle_pyout(self, msg):
369 371 """ Handle display hook output.
370 372 """
371 373 if not self._hidden and self._is_from_this_session(msg):
372   - self._append_plain_text(msg['content']['data']['text/plain'] + '\n')
  374 + data = msg['content']['data']
  375 + if isinstance(data, basestring):
  376 + # plaintext data from pure Python kernel
  377 + text = data
  378 + else:
  379 + # formatted output from DisplayFormatter (IPython kernel)
  380 + text = data.get('text/plain', '')
  381 + self._append_plain_text(text + '\n')
373 382
374 383 def _handle_stream(self, msg):
375 384 """ Handle stdout, stderr, and stdin.

0 comments on commit b5570f7

Please sign in to comment.
Something went wrong with that request. Please try again.