Get a module object from a compiler, given module object, string name of a module, and (optionally) the calling frame; otherwise, raise an error.
(module=None, compiler=None, calling_frame=False)
| 710 | |
| 711 | |
| 712 | def get_compiler_module(module=None, compiler=None, calling_frame=False): |
| 713 | """Get a module object from a compiler, given module object, |
| 714 | string name of a module, and (optionally) the calling frame; otherwise, |
| 715 | raise an error.""" |
| 716 | |
| 717 | module = getattr(compiler, "module", None) or module |
| 718 | |
| 719 | if isinstance(module, str): |
| 720 | module = importlib.import_module(mangle(module)) |
| 721 | |
| 722 | if calling_frame and not module: |
| 723 | module = calling_module(n=2) |
| 724 | |
| 725 | if not inspect.ismodule(module): |
| 726 | raise TypeError("Invalid module type: {}".format(type(module))) |
| 727 | |
| 728 | return module |
| 729 | |
| 730 | |
| 731 | def hy_eval( |
no test coverage detected