(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
)
| 777 | return self |
| 778 | |
| 779 | async def __aexit__( |
| 780 | self, |
| 781 | exc_type: type[BaseException] | None, |
| 782 | exc_val: BaseException | None, |
| 783 | exc_tb: TracebackType | None, |
| 784 | ) -> None: |
| 785 | ops = self._ops |
| 786 | ui_updates = self._ui_updates |
| 787 | cells_to_run = self._cells_to_run |
| 788 | self._ops = [] |
| 789 | self._pending_adds = {} |
| 790 | self._ui_updates = [] |
| 791 | self._cells_to_run = set() |
| 792 | |
| 793 | await self.close_screenshot_session() |
| 794 | |
| 795 | if exc_type is not None: |
| 796 | self._packages._reset() |
| 797 | return # let exception propagate, discard queued ops |
| 798 | |
| 799 | # Flush queued package ops before cell ops so newly added |
| 800 | # cells can import newly installed packages. |
| 801 | package_ops = await self._packages._flush() |
| 802 | |
| 803 | if ops: |
| 804 | _validate_ops(ops) |
| 805 | if not self._skip_validation: |
| 806 | self._dry_run_compile(ops) |
| 807 | await self._apply_ops(ops, cells_to_run) |
| 808 | elif cells_to_run: |
| 809 | code_lookup = {c.id: c.code for c in self._document.cells} |
| 810 | await self._kernel.run( |
| 811 | [ |
| 812 | ExecuteCellCommand( |
| 813 | cell_id=cid, |
| 814 | code=code_lookup[cid], |
| 815 | ) |
| 816 | for cid in cells_to_run |
| 817 | ] |
| 818 | ) |
| 819 | |
| 820 | # Flush queued UI updates as a single batch. |
| 821 | if ui_updates: |
| 822 | object_ids, values = zip(*ui_updates, strict=False) |
| 823 | await self._kernel.set_ui_element_value( |
| 824 | UpdateUIElementCommand( |
| 825 | object_ids=list(object_ids), |
| 826 | values=list(values), |
| 827 | ), |
| 828 | notify_frontend=True, |
| 829 | ) |
| 830 | |
| 831 | # Print a summary of what was applied. |
| 832 | self._print_summary(ops, package_ops, ui_updates, cells_to_run) |
| 833 | |
| 834 | # ------------------------------------------------------------------ |
| 835 | # Summary |
nothing calls this directly
no test coverage detected