Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abdfef6

Browse files
committed
Deal with some changes in the IPython 3.x API
The IPython API is ever moving and the newest version again breaks vim-ipython. This PR adds some try/catch blocks to deal with the API changes.
1 parent 5876b48 commit abdfef6

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

ftplugin/python/vim_ipython.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,25 @@ def km_from_string(s=''):
172172
# 0.13
173173
kc = km
174174
kc.start_channels()
175-
send = kc.shell_channel.execute
175+
176+
try:
177+
send = kc.execute
178+
except AttributeError:
179+
# < 3.0
180+
send = kc.shell_channel.execute
176181

177182
#XXX: backwards compatibility for IPython < 0.13
178-
import inspect
179-
sc = kc.shell_channel
180-
num_oinfo_args = len(inspect.getargspec(sc.object_info).args)
181-
if num_oinfo_args == 2:
182-
# patch the object_info method which used to only take one argument
183-
klass = sc.__class__
184-
klass._oinfo_orig = klass.object_info
185-
klass.object_info = lambda s,x,y: s._oinfo_orig(x)
183+
try:
184+
import inspect
185+
sc = kc.shell_channel
186+
num_oinfo_args = len(inspect.getargspec(sc.object_info).args)
187+
if num_oinfo_args == 2:
188+
# patch the object_info method which used to only take one argument
189+
klass = sc.__class__
190+
klass._oinfo_orig = klass.object_info
191+
klass.object_info = lambda s,x,y: s._oinfo_orig(x)
192+
except:
193+
pass
186194

187195
#XXX: backwards compatibility for IPython < 1.0
188196
if not hasattr(kc, 'iopub_channel'):
@@ -569,7 +577,12 @@ def set_pid():
569577
"""
570578
global pid
571579
lines = '\n'.join(['import os', '_pid = os.getpid()'])
572-
msg_id = send(lines, silent=True, user_variables=['_pid'])
580+
581+
try:
582+
msg_id = send(lines, silent=True, user_variables=['_pid'])
583+
except TypeError: # change in IPython 3.0+
584+
msg_id = send(lines, silent=True, user_expressions={'_pid':'_pid'})
585+
573586
# wait to get message back from kernel
574587
try:
575588
child = get_child_msg(msg_id)

0 commit comments

Comments
 (0)