Assert importlib specs

This commit is contained in:
Marko Durkovic 2021-07-05 10:28:59 +02:00
parent a8baffcbd7
commit ea40c74133
2 changed files with 4 additions and 1 deletions

View File

@ -98,6 +98,8 @@ def compile_lines(lines: List[str]) -> ModuleType:
Compiled and loaded module.
"""
module = module_from_spec(spec_from_loader('tmpmod', loader=None))
spec = spec_from_loader('tmpmod', loader=None)
assert spec
module = module_from_spec(spec)
exec('\n'.join(lines), module.__dict__) # pylint: disable=exec-used
return module

View File

@ -92,6 +92,7 @@ def register_types(typs: Typesdict) -> None:
code = generate_python_code(typs)
name = 'rosbags.usertypes'
spec = spec_from_loader(name, loader=None)
assert spec
module = module_from_spec(spec)
sys.modules[name] = module
exec(code, module.__dict__) # pylint: disable=exec-used