Skip to content

Commit 654c9fe

Browse files
committed
set_next_input: squash multiple calls from the same cell execution
* When calling multiple times set_next_input in a single cell execution, we only keep the last input. * Added generic support to PayloadManager for updating (instead of appending) payloads from a given 'source'. Closes #1349
1 parent bd66ff0 commit 654c9fe

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

IPython/core/payload.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ class PayloadManager(Configurable):
2929

3030
_payload = List([])
3131

32-
def write_payload(self, data):
32+
def write_payload(self, data, update=False):
3333
if not isinstance(data, dict):
3434
raise TypeError('Each payload write must be a dict, got: %r' % data)
35+
36+
if update and 'source' in data:
37+
source = data['source']
38+
for i,pl in enumerate(self._payload):
39+
if 'source' in pl and pl['source'] == source:
40+
self._payload[i] = data
41+
return
42+
3543
self._payload.append(data)
3644

3745
def read_payload(self):

IPython/kernel/zmq/zmqshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def set_next_input(self, text):
583583
source='set_next_input',
584584
text=text
585585
)
586-
self.payload_manager.write_payload(payload)
586+
self.payload_manager.write_payload(payload, update=True)
587587

588588
#-------------------------------------------------------------------------
589589
# Things related to magics

0 commit comments

Comments
 (0)