Skip to content

Commit 9eeebcf

Browse files
committed
Move guard into Rust.
1 parent e4a1d95 commit 9eeebcf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crates/processing_pyo3/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ fn _present(module: &Bound<'_, PyModule>) -> PyResult<()> {
161161

162162
#[pyfunction]
163163
#[pyo3(pass_module)]
164-
fn _readback_png(module: &Bound<'_, PyModule>) -> PyResult<Vec<u8>> {
165-
let graphics =
166-
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
167-
graphics.readback_png()
164+
fn _readback_png(module: &Bound<'_, PyModule>) -> PyResult<Option<Vec<u8>>> {
165+
let Some(graphics) = get_graphics(module)? else {
166+
return Ok(None);
167+
};
168+
graphics.readback_png().map(Some)
168169
}
169170

170171
#[pyfunction]

crates/processing_pyo3/src/python/jupyter_post_execute.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import IPython.display as _ipy_display
33

44
def _processing_post_execute(result):
5-
if getattr(processing, '_graphics', None) is None:
6-
return
75
processing._present()
86
png_data = processing._readback_png()
9-
_ipy_display.display(_ipy_display.Image(data=bytes(png_data)))
7+
if png_data is not None:
8+
_ipy_display.display(_ipy_display.Image(data=bytes(png_data)))
109

1110
get_ipython().events.register('post_run_cell', _processing_post_execute)

0 commit comments

Comments
 (0)