From 8a6c9a7fc5519ccc0cb7508ce369f411020a63db 2010-08-19 17:46:49 From: Brian Granger Date: 2010-08-19 17:46:49 Subject: [PATCH] Fixes to docs and InteractiveShell.instance() * Updated messaging docs to say that the prompt informtion always is returned in execute_reply. * Started to fix InteractiveShell.instance() to properly handle subclasses. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 485c164..591058e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -126,6 +126,9 @@ class SeparateStr(Str): value = value.replace('\\n','\n') return super(SeparateStr, self).validate(obj, value) +class MultipleInstanceError(Exception): + pass + #----------------------------------------------------------------------------- # Main IPython class @@ -268,14 +271,17 @@ class InteractiveShell(Configurable, Magic): """Returns a global InteractiveShell instance.""" if not hasattr(cls, "_instance"): cls._instance = cls(*args, **kwargs) - print cls - print cls._instance # Now make sure that the instance will also be returned by # the subclasses instance attribute. - for subclass in cls.mro(): + for subclass in cls.mro()[1:]: if issubclass(subclass, InteractiveShell): - print subclass - subclass._instance = cls._instance + if not hasattr(subclass, '_instance'): + subclass._instance = cls._instance + else: + raise MultipleInstanceError( + 'Multiple conflicting subclass of ' + 'InteractiveShell have been created.' + ) return cls._instance @classmethod diff --git a/docs/source/development/messaging.txt b/docs/source/development/messaging.txt index bd5a80a..396d933 100644 --- a/docs/source/development/messaging.txt +++ b/docs/source/development/messaging.txt @@ -164,12 +164,6 @@ Message type: ``execute_reply``:: # One of: 'ok' OR 'error' OR 'abort' 'status' : str, - # Any additional data depends on status value - } - -When status is 'ok', the following extra fields are present:: - - { # This has the same structure as the output of a prompt request, but is # for the client to set up the *next* prompt (with identical limitations # to a prompt request) @@ -186,7 +180,11 @@ When status is 'ok', the following extra fields are present:: # to correct the previously written number in-place, terminal ones may # re-print a corrected one if desired. 'prompt_number' : int, + } + +When status is 'ok', the following extra fields are present:: + { # The kernel will often transform the input provided to it. This # contains the transformed code, which is what was actually executed. 'transformed_code' : str,