From ce37ca2bf9c12a38fec4b1dac650e621a305c399 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 13 Jun 2023 20:51:09 -0400 Subject: [PATCH] Relax the the stipulation of `pre_export()` being a generator function. There are some things that exist in `pre_export()`, eg animations, that don't actually generate anything that needs to be memory managed. So, it's ok if `pre_export()` isn't actually a generator function. It does need to return either a generator or `None`, however. --- korman/exporter/convert.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index c320c6a..0728271 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -519,11 +519,14 @@ class Exporter: # yield my_object # my_object.foo = bar # ``` - assert inspect.isgeneratorfunction(proc), "pre_export should be a generator function" pre_result = proc(self, bo) + assert ( + inspect.isgenerator(pre_result) or pre_result is None, + "pre_export() should return a generator or None" + ) try: gen_result = None - while True: + while pre_result is not None: gen_result = pre_result.send(gen_result) if gen_result is not None: gen_result = handle_temporary(gen_result, bo) @@ -531,7 +534,8 @@ class Exporter: if e.value is not None: handle_temporary(e.value, bo) finally: - pre_result.close() + if pre_result is not None: + pre_result.close() with indent(): for bl_obj in self._objects: