From 38865addf9129518e287b665e87595a6e0252e79 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 29 Oct 2023 17:15:45 -0400 Subject: [PATCH] fix some typing/lint issues --- vyper/cli/vyper_compile.py | 1 + vyper/cli/vyper_json.py | 12 ++++++------ vyper/compiler/input_bundle.py | 15 ++++++++------- vyper/semantics/analysis/module.py | 7 +++---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 1e24fe64e5..b15c57f296 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -235,6 +235,7 @@ def compile_files( contract_sources: ContractCodes = dict() for file_name in input_files: + file_path = Path(file_name) contract_sources[file_path] = input_bundle.load_file(Path(file_path)) storage_layouts = dict() diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 0bccd62f24..74faa5e612 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -170,15 +170,15 @@ def get_compilation_targets(input_dict: dict) -> ContractCodes: f"Calculated keccak of '{path}' does not match keccak given in input JSON" ) if path in ret: - raise JSONError(f"Contract namespace collision: {key}") + raise JSONError(f"Contract namespace collision: {path}") - ret[path] = value["content"] + ret[path] = value for path, value in input_dict.get("interfaces", {}).items(): - if key in interface_sources: - raise JSONError(f"Interface namespace collision: {key}") + if path in ret: + raise JSONError(f"Interface namespace collision: {path}") - ret[path] = value + ret[path] = {"content": value} return ret @@ -208,7 +208,7 @@ def get_input_dict_output_formats(input_dict: Dict, contract_sources: ContractCo if path == "*": output_keys = list(contract_sources.keys()) else: - output_keys = [_standardize_path(path)] + output_keys = [Path(path)] if output_keys[0] not in contract_sources: raise JSONError(f"outputSelection references unknown contract '{output_keys[0]}'") diff --git a/vyper/compiler/input_bundle.py b/vyper/compiler/input_bundle.py index 024bde2226..324d4d6564 100644 --- a/vyper/compiler/input_bundle.py +++ b/vyper/compiler/input_bundle.py @@ -98,6 +98,7 @@ def _load_from_path(self, path: Path) -> CompilerInput: source_id = super()._generate_source_id(path) return FileInput(source_id, path, code) + # fake filesystem for JSON inputs. takes a base path, and `load_file()` # "reads" the file from the JSON input. Note that this input bundle type # never actually interacts with the filesystem -- it is guaranteed to be pure! @@ -107,20 +108,20 @@ class JSONInputBundle(InputBundle): def _load_from_path(self, path: PurePath) -> CompilerInput: try: - contents = self.input_json[path] + value = self.input_json[path] except KeyError: raise _NotFound(path) source_id = super()._generate_source_id(path) - if isinstance(contents, str): - return FileInput(source_id, path, code) + if "content" in value: + return FileInput(source_id, path, value["content"]) - if "abi" in contents: - return ABIInput(source_id, path, contents["abi"]) + if "abi" in value: + return ABIInput(source_id, path, value["abi"]) - if isinstance(contents, list): - return ABIInput(source_id, path, contents) + if isinstance(value, list): + return ABIInput(source_id, path, value) # TODO: ethPM support # if isinstance(contents, dict) and "contractTypes" in contents: diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 597862088e..c2fd9c563a 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -6,11 +6,10 @@ import vyper.builtins.interfaces from vyper import ast as vy_ast -from vyper.compiler.input_bundle import ABIInput, CompilerInput, InputBundle, VyFile +from vyper.compiler.input_bundle import InputBundle from vyper.evm.opcodes import version_check from vyper.exceptions import ( CallViolation, - CompilerPanic, ExceptionList, InvalidLiteral, InvalidType, @@ -341,8 +340,8 @@ def _load_import(self, level: int, module: str) -> InterfaceT: path = _import_to_path(level, module) try: 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) + interface_ast = vy_ast.parse_to_ast(file.source_code, contract_name=file.path) + return InterfaceT.from_ast(interface_ast) except FileNotFoundError: file = self.input_bundle.load_file(path.with_suffix(".json")) abi = json.loads(file.source_code)