Skip to content

Fix ipywidgets Output context manager not working with MetaKernel#365

Merged
blink1073 merged 2 commits intoCalysto:mainfrom
blink1073:fix-217
Mar 13, 2026
Merged

Fix ipywidgets Output context manager not working with MetaKernel#365
blink1073 merged 2 commits intoCalysto:mainfrom
blink1073:fix-217

Conversation

@blink1073
Copy link
Copy Markdown
Contributor

@blink1073 blink1073 commented Mar 13, 2026

Summary

  • ipywidgets.Output's with output: context manager failed to route output to the widget when used with MetaKernel because get_ipython() returned None and comm.kernel was None at construction time
  • Fixed by overriding comm.create_comm in MetaKernel.__init__ to pre-set kernel=self on newly created comms, enabling the comm.kernel fallback path in Output.__enter__ to call kernel.get_parent() and set msg_id correctly
  • Added a regression test that simulates an execute request and verifies msg_id is set/cleared correctly when entering/exiting the context manager

Closes #217

Test plan

  • just test passes (458 passed, 11 skipped)
  • New test TestIpywidgetsOutputContextManager::test_output_widget_context_manager_sets_msg_id covers the regression

Ensure comm objects created by MetaKernel have kernel=self set at
construction time. This allows ipywidgets.Output.__enter__ to reach
kernel.get_parent() via the comm.kernel fallback path and correctly
set msg_id, making the `with output:` context manager route output
to the widget as expected.

Closes Calysto#217
@blink1073 blink1073 added the bug label Mar 13, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.92%. Comparing base (cca4a2e) to head (e74d764).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
metakernel/_metakernel.py 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
- Coverage   90.95%   90.92%   -0.04%     
==========================================
  Files          51       51              
  Lines        2875     2886      +11     
  Branches      403      404       +1     
==========================================
+ Hits         2615     2624       +9     
- Misses        181      183       +2     
  Partials       79       79              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blink1073 blink1073 merged commit e203cf8 into Calysto:main Mar 13, 2026
25 checks passed
@blink1073 blink1073 deleted the fix-217 branch March 13, 2026 03:34
@blink1073 blink1073 mentioned this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

context manager version of outputs widget does not work with metakernel

2 participants