Skip to content

Commit 0bd8e20

Browse files
committed
Fix the performance issue
1 parent 4b298ad commit 0bd8e20

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

IPython/core/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class HistoryOutput:
590590
output_type: typing.Literal[
591591
"out_stream", "err_stream", "display_data", "execute_result"
592592
]
593-
bundle: typing.Dict[str, str]
593+
bundle: typing.Dict[str, str | list[str]]
594594

595595

596596
class HistoryManager(HistoryAccessor):

IPython/core/interactiveshell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,11 +3063,11 @@ def write(data, *args, **kwargs):
30633063
output_stream = outputs[-1]
30643064
if output_stream is None:
30653065
output_stream = HistoryOutput(
3066-
output_type=output_type, bundle={"stream": ""}
3066+
output_type=output_type, bundle={"stream": []}
30673067
)
30683068
outputs_by_counter[execution_count].append(output_stream)
30693069

3070-
output_stream.bundle["stream"] += data # Append to existing stream
3070+
output_stream.bundle["stream"].append(data) # Append to existing stream
30713071
return result
30723072

30733073
stream.write = write

IPython/core/magics/basic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,11 @@ def notebook(self, s):
571571
for output in outputs[execution_count]:
572572
for mime_type, data in output.bundle.items():
573573
if output.output_type == "out_stream":
574-
cell.outputs.append(v4.new_output("stream", text=[data]))
574+
text = data if isinstance(data, list) else [data]
575+
cell.outputs.append(v4.new_output("stream", text=text))
575576
elif output.output_type == "err_stream":
576-
err_output = v4.new_output("stream", text=[data])
577+
text = data if isinstance(data, list) else [data]
578+
err_output = v4.new_output("stream", text=text)
577579
err_output.name = "stderr"
578580
cell.outputs.append(err_output)
579581
elif output.output_type == "execute_result":

0 commit comments

Comments
 (0)