Browse Source

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.
pull/374/head
Adam Johnson 1 year ago
parent
commit
ce37ca2bf9
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 10
      korman/exporter/convert.py

10
korman/exporter/convert.py

@ -519,11 +519,14 @@ class Exporter:
# yield my_object # yield my_object
# my_object.foo = bar # my_object.foo = bar
# ``` # ```
assert inspect.isgeneratorfunction(proc), "pre_export should be a generator function"
pre_result = proc(self, bo) pre_result = proc(self, bo)
assert (
inspect.isgenerator(pre_result) or pre_result is None,
"pre_export() should return a generator or None"
)
try: try:
gen_result = None gen_result = None
while True: while pre_result is not None:
gen_result = pre_result.send(gen_result) gen_result = pre_result.send(gen_result)
if gen_result is not None: if gen_result is not None:
gen_result = handle_temporary(gen_result, bo) gen_result = handle_temporary(gen_result, bo)
@ -531,7 +534,8 @@ class Exporter:
if e.value is not None: if e.value is not None:
handle_temporary(e.value, bo) handle_temporary(e.value, bo)
finally: finally:
pre_result.close() if pre_result is not None:
pre_result.close()
with indent(): with indent():
for bl_obj in self._objects: for bl_obj in self._objects:

Loading…
Cancel
Save