From a2b21b71d774c96a5358ed3f9af990f0322f335f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 29 Oct 2023 17:08:44 -0400 Subject: [PATCH] clean up _resolve_import --- vyper/semantics/analysis/module.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index b5b6346803..597862088e 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -329,29 +329,24 @@ def _add_import( ) with self.input_bundle.search_path(builtins_path): - file = self._resolve_import(level, qualified_module_name) - - if isinstance(file, VyFile): - interface_ast = vy_ast.parse_to_ast(file.source_code, contract_name=file.path) - type_ = InterfaceT.from_ast(interface_ast) - elif isinstance(file, ABIInput): - type_ = InterfaceT.from_json_abi(file.path, file.abi) - else: # pragma: nocover - raise CompilerPanic(f"Unknown interface format: {type(file)}") + type_ = self._load_import(level, qualified_module_name) try: self.namespace[alias] = type_ except VyperException as exc: raise exc.with_annotation(node) from None - def _resolve_import(self, level: int, module: str) -> CompilerInput: + # load an InterfaceT from an import + def _load_import(self, level: int, module: str) -> InterfaceT: path = _import_to_path(level, module) try: - return self.input_bundle.load_file(path.with_suffix(".vy")) + file = self.input_bundle.load_file(path.with_suffix(".vy")) + ast = vy_ast.parse_to_ast(file.source_code, contract_name=file.path) + InterfaceT.from_ast(interface_ast) except FileNotFoundError: file = self.input_bundle.load_file(path.with_suffix(".json")) abi = json.loads(file.source_code) - return ABIInput(file.path, abi) + return InterfaceT.from_json_abi(file.path, abi) # convert an import to a path (without suffix)