@_with_ast_loc_deps<EOL>def _import_to_py_ast(ctx: GeneratorContext, node: Import) -> GeneratedPyAST:
assert node.op == NodeOp.IMPORT<EOL>last = None<EOL>deps: List[ast.AST] = []<EOL>for alias in node.aliases:<EOL><INDENT>safe_name = munge(alias.name)<EOL>try:<EOL><INDENT>module = importlib.import_module(safe_name)<EOL>if alias.alias is not None:<EOL><INDENT>ctx.add_import(sym.symbol(alias.name), module, sym.symbol(alias.alias))<EOL><DEDENT>else:<EOL><INDENT>ctx.add_import(sym.symbol(alias.name), module)<EOL><DEDENT><DEDENT>except ModuleNotFoundError as e:<EOL><INDENT>raise ImportError(<EOL>f"<STR_LIT>", node.form, node<EOL>) from e<EOL><DEDENT>py_import_alias = (<EOL>munge(alias.alias)<EOL>if alias.alias is not None<EOL>else safe_name.split("<STR_LIT:.>", maxsplit=<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>)<EOL>deps.append(<EOL>ast.Assign(<EOL>targets=[ast.Name(id=py_import_alias, ctx=ast.Store())],<EOL>value=ast.Call(<EOL>func=_load_attr("<STR_LIT>"),<EOL>args=[ast.Str(safe_name)],<EOL>keywords=[],<EOL>),<EOL>)<EOL>)<EOL>last = ast.Name(id=py_import_alias, ctx=ast.Load())<EOL>deps.append(<EOL>ast.Call(<EOL>func=_load_attr(f"<STR_LIT>"),<EOL>args=[<EOL>ast.Call(<EOL>func=_NEW_SYM_FN_NAME, args=[ast.Str(safe_name)], keywords=[]<EOL>),<EOL>last,<EOL>],<EOL>keywords=[],<EOL>)<EOL>)<EOL><DEDENT>assert last is not None, "<STR_LIT>"<EOL>return GeneratedPyAST(node=last, dependencies=deps)<EOL>
Return a Python AST node for a Basilisp `import*` expression.