Mutually recursive struct types defined inside functions don't work (and probably never will). To avoid populating a bunch of test structs in the top level of this module, we instead create a temporary module per test to exec whatever is needed for that test
(code)
| 8 | |
| 9 | @contextmanager |
| 10 | def temp_module(code): |
| 11 | """Mutually recursive struct types defined inside functions don't work (and |
| 12 | probably never will). To avoid populating a bunch of test structs in the |
| 13 | top level of this module, we instead create a temporary module per test to |
| 14 | exec whatever is needed for that test""" |
| 15 | code = textwrap.dedent(code) |
| 16 | name = f"temp_{uuid.uuid4().hex}" |
| 17 | mod = types.ModuleType(name) |
| 18 | sys.modules[name] = mod |
| 19 | try: |
| 20 | exec(code, mod.__dict__) |
| 21 | yield mod |
| 22 | finally: |
| 23 | sys.modules.pop(name, None) |
| 24 | |
| 25 | |
| 26 | @contextmanager |
no outgoing calls
searching dependent graphs…