From e599b6570522c5dcf983ac11d87984fd1a8f4341 2014-05-07 05:39:43 From: MinRK Date: 2014-05-07 05:39:43 Subject: [PATCH] remove user_variables leave only user_expressions --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 4ab5569..529ecf4 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2395,7 +2395,7 @@ class InteractiveShell(SingletonConfigurable): def _user_obj_error(self): """return simple exception dict - for use in user_variables / expressions + for use in user_expressions """ etype, evalue, tb = self._get_exc_info() @@ -2413,7 +2413,7 @@ class InteractiveShell(SingletonConfigurable): def _format_user_obj(self, obj): """format a user object to display dict - for use in user_expressions / variables + for use in user_expressions """ data, md = self.display_formatter.format(obj) @@ -2424,30 +2424,6 @@ class InteractiveShell(SingletonConfigurable): } return value - def user_variables(self, names): - """Get a list of variable names from the user's namespace. - - Parameters - ---------- - names : list of strings - A list of names of variables to be read from the user namespace. - - Returns - ------- - A dict, keyed by the input names and with the rich mime-type repr(s) of each value. - Each element will be a sub-dict of the same form as a display_data message. - """ - out = {} - user_ns = self.user_ns - - for varname in names: - try: - value = self._format_user_obj(user_ns[varname]) - except: - value = self._user_obj_error() - out[varname] = value - return out - def user_expressions(self, expressions): """Evaluate a dict of expressions in the user's namespace. diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index b01dc6d..f5ceb03 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -4,22 +4,11 @@ Historically the main classes in interactiveshell have been under-tested. This module should grow as many single-method tests as possible to trap many of the recurring bugs we seem to encounter with high-level interaction. - -Authors -------- -* Fernando Perez """ -#----------------------------------------------------------------------------- -# Copyright (C) 2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- -# stdlib +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + import ast import os import signal @@ -33,10 +22,8 @@ except ImportError: import mock from os.path import join -# third-party import nose.tools as nt -# Our own from IPython.core.inputtransformer import InputTransformer from IPython.testing.decorators import skipif, skip_win32, onlyif_unicode_paths from IPython.testing import tools as tt @@ -645,7 +632,7 @@ def test_user_variables(): ip.user_ns['dummy'] = d = DummyRepr() keys = set(['dummy', 'doesnotexist']) - r = ip.user_variables(keys) + r = ip.user_expressions({ key:key for key in keys}) nt.assert_equal(keys, set(r.keys())) dummy = r['dummy'] @@ -660,7 +647,7 @@ def test_user_variables(): dne = r['doesnotexist'] nt.assert_equal(dne['status'], 'error') - nt.assert_equal(dne['ename'], 'KeyError') + nt.assert_equal(dne['ename'], 'NameError') # back to text only ip.display_formatter.active_types = ['text/plain'] diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 5830331..a7a5b56 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -302,7 +302,6 @@ var IPython = (function (IPython) { * @param {object} [options] * @param [options.silent=false] {Boolean} * @param [options.user_expressions=empty_dict] {Dict} - * @param [options.user_variables=empty_list] {List od Strings} * @param [options.allow_stdin=false] {Boolean} true|false * * @example @@ -312,7 +311,6 @@ var IPython = (function (IPython) { * * options = { * silent : true, - * user_variables : [], * user_expressions : {}, * allow_stdin : false * } @@ -342,7 +340,6 @@ var IPython = (function (IPython) { code : code, silent : true, store_history : false, - user_variables : [], user_expressions : {}, allow_stdin : false }; diff --git a/IPython/kernel/channels.py b/IPython/kernel/channels.py index 3b64865..a85a0ef 100644 --- a/IPython/kernel/channels.py +++ b/IPython/kernel/channels.py @@ -1,20 +1,10 @@ -"""Base classes to manage a Client's interaction with a running kernel -""" +"""Base classes to manage a Client's interaction with a running kernel""" -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from __future__ import absolute_import -# Standard library imports import atexit import errno from threading import Thread @@ -227,7 +217,7 @@ class ShellChannel(ZMQSocketChannel): raise NotImplementedError('call_handlers must be defined in a subclass.') def execute(self, code, silent=False, store_history=True, - user_variables=None, user_expressions=None, allow_stdin=None): + user_expressions=None, allow_stdin=None): """Execute code in the kernel. Parameters @@ -243,11 +233,6 @@ class ShellChannel(ZMQSocketChannel): If set, the kernel will store command history. This is forced to be False if silent is True. - user_variables : list, optional - A list of variable names to pull from the user's namespace. They - will come back as a dict with these names as keys and their - :func:`repr` as values. - user_expressions : dict, optional A dict mapping names to expressions to be evaluated in the user's dict. The expression values are returned as strings formatted using @@ -264,8 +249,6 @@ class ShellChannel(ZMQSocketChannel): ------- The msg_id of the message sent. """ - if user_variables is None: - user_variables = [] if user_expressions is None: user_expressions = {} if allow_stdin is None: @@ -275,13 +258,11 @@ class ShellChannel(ZMQSocketChannel): # Don't waste network traffic if inputs are invalid if not isinstance(code, string_types): raise ValueError('code %r must be a string' % code) - validate_string_list(user_variables) validate_string_dict(user_expressions) # Create class for content/msg creation. Related to, but possibly # not in Session. content = dict(code=code, silent=silent, store_history=store_history, - user_variables=user_variables, user_expressions=user_expressions, allow_stdin=allow_stdin, ) diff --git a/IPython/kernel/channelsabc.py b/IPython/kernel/channelsabc.py index 43da3ef..12aadd6 100644 --- a/IPython/kernel/channelsabc.py +++ b/IPython/kernel/channelsabc.py @@ -1,11 +1,7 @@ """Abstract base classes for kernel client channels""" -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import abc @@ -42,7 +38,7 @@ class ShellChannelABC(ChannelABC): @abc.abstractmethod def execute(self, code, silent=False, store_history=True, - user_variables=None, user_expressions=None, allow_stdin=None): + user_expressions=None, allow_stdin=None): pass @abc.abstractmethod diff --git a/IPython/kernel/inprocess/channels.py b/IPython/kernel/inprocess/channels.py index 8ff95b5..cad01d2 100644 --- a/IPython/kernel/inprocess/channels.py +++ b/IPython/kernel/inprocess/channels.py @@ -1,23 +1,13 @@ -""" A kernel client for in-process kernels. """ +"""A kernel client for in-process kernels.""" -#----------------------------------------------------------------------------- -# Copyright (C) 2012 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -# IPython imports from IPython.kernel.channelsabc import ( ShellChannelABC, IOPubChannelABC, HBChannelABC, StdInChannelABC, ) -# Local imports from .socket import DummySocket #----------------------------------------------------------------------------- @@ -94,11 +84,10 @@ class InProcessShellChannel(InProcessChannel): #-------------------------------------------------------------------------- def execute(self, code, silent=False, store_history=True, - user_variables=[], user_expressions={}, allow_stdin=None): + user_expressions={}, allow_stdin=None): if allow_stdin is None: allow_stdin = self.allow_stdin content = dict(code=code, silent=silent, store_history=store_history, - user_variables=user_variables, user_expressions=user_expressions, allow_stdin=allow_stdin) msg = self.client.session.msg('execute_request', content) diff --git a/IPython/kernel/tests/test_message_spec.py b/IPython/kernel/tests/test_message_spec.py index cd28943..4664fbf 100644 --- a/IPython/kernel/tests/test_message_spec.py +++ b/IPython/kernel/tests/test_message_spec.py @@ -75,7 +75,8 @@ class RMessage(Reference): def check(self, d): super(RMessage, self).check(d) RHeader().check(self.header) - RHeader().check(self.parent_header) + if self.parent_header: + RHeader().check(self.parent_header) class RHeader(Reference): msg_id = Unicode() @@ -99,7 +100,6 @@ class ExecuteReply(Reference): class ExecuteReplyOkay(Reference): payload = List(Dict) - user_variables = Dict() user_expressions = Dict() @@ -294,28 +294,6 @@ def test_execute_inc(): nt.assert_equal(count_2, count+1) -def test_user_variables(): - flush_channels() - - msg_id, reply = execute(code='x=1', user_variables=['x']) - user_variables = reply['user_variables'] - nt.assert_equal(user_variables, {u'x': { - u'status': u'ok', - u'data': {u'text/plain': u'1'}, - u'metadata': {}, - }}) - - -def test_user_variables_fail(): - flush_channels() - - msg_id, reply = execute(code='x=1', user_variables=['nosuchname']) - user_variables = reply['user_variables'] - foo = user_variables['nosuchname'] - nt.assert_equal(foo['status'], 'error') - nt.assert_equal(foo['ename'], 'KeyError') - - def test_user_expressions(): flush_channels() diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 69b08b0..b46239e 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -424,16 +424,12 @@ class Kernel(Configurable): # At this point, we can tell whether the main code execution succeeded - # or not. If it did, we proceed to evaluate user_variables/expressions + # or not. If it did, we proceed to evaluate user_expressions if reply_content['status'] == 'ok': - reply_content[u'user_variables'] = \ - shell.user_variables(content.get(u'user_variables', [])) reply_content[u'user_expressions'] = \ shell.user_expressions(content.get(u'user_expressions', {})) else: - # If there was an error, don't even try to compute variables or - # expressions - reply_content[u'user_variables'] = {} + # If there was an error, don't even try to compute expressions reply_content[u'user_expressions'] = {} # Payloads should be retrieved regardless of outcome, so we can both diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index c57d036..d4181fd 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -1285,7 +1285,7 @@ class Client(HasTraits): if not isinstance(metadata, dict): raise TypeError("metadata must be dict, not %s" % type(metadata)) - content = dict(code=code, silent=bool(silent), user_variables=[], user_expressions={}) + content = dict(code=code, silent=bool(silent), user_expressions={}) msg = self.session.send(socket, "execute_request", content=content, ident=ident,