Skip to content

Store displays under the running cell's execution count - #1604

Open
MichengLiang wants to merge 1 commit into
ipython:mainfrom
MichengLiang:fix-display-history-count
Open

MichengLiang wants to merge 1 commit into
ipython:mainfrom
MichengLiang:fix-display-history-count

Conversation

@MichengLiang

Copy link
Copy Markdown

Fixes #1602.

run_cell increments execution_count before the cell runs, so while a cell runs (and in its post_execute hooks, which is the case ipython/ipython#14998 handled) the cell's own count is execution_count - 1. IPython's own DisplayPublisher.publish uses execution_count - 1; ZMQDisplayPublisher.publish used execution_count outside post_execute, so with store_display_history=True a display was recorded under the next cell and %notebook exported it there.

  • ZMQDisplayPublisher.publish stores under execution_count - 1 in both cases.
  • test_display_stored_in_history mocked execution_count = 1 while expecting the display under cell 1, which pinned the wrong count. It now mocks the count as it is while cell 1 runs (2), with and without _in_post_execute.
  • test_display_history_uses_the_cell_execution_count checks it end to end in a kernel started with --ZMQDisplayPublisher.store_display_history=True; it fails before the change (the cell's entry is empty) and passes after.

Found while building a tool around ipykernel subshells; investigated and written with an AI assistant (🤖🤖).

run_cell increments execution_count before the cell runs, so while a cell
runs (and in its post_execute hooks) the cell's own count is
execution_count - 1, as IPython's own DisplayPublisher uses. The ZMQ
publisher used execution_count outside post_execute, so with
store_display_history=True a display was recorded under the next cell and
%notebook exported it there.

The unit test mocked execution_count=1 while expecting cell 1, which pinned
the wrong count; it now mocks the count during cell 1 (2) and covers the
post_execute case. A kernel test checks the stored execution count end to
end.

Fixes ipython#1602

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

store_display_history records a cell's display under the next execution count

1 participant