From fb72306987377aa58818633e6fd734119aa8ab32 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 11 Oct 2024 13:31:51 +0200 Subject: [PATCH 01/34] set is_interface based on the suffix of an input file --- vyper/compiler/phases.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 97df73cdae..3e38b4aa1b 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -287,7 +287,8 @@ def generate_annotated_ast(vyper_module: vy_ast.Module, input_bundle: InputBundl vyper_module = copy.deepcopy(vyper_module) with input_bundle.search_path(Path(vyper_module.resolved_path).parent): # note: analyze_module does type inference on the AST - analyze_module(vyper_module, input_bundle) + is_interface = vyper_module.resolved_path.endswith(".vyi") + analyze_module(vyper_module, input_bundle, is_interface=is_interface) return vyper_module From 8bc61ed95c0e8051e6bd15ff7c548cac15ab9576 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 11 Oct 2024 14:41:30 +0200 Subject: [PATCH 02/34] construct ir_runtime only if input isn't interface --- vyper/compiler/output.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index d04b677b3e..a96c66089c 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -254,7 +254,8 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict: def build_abi_output(compiler_data: CompilerData) -> list: module_t = compiler_data.annotated_vyper_module._metadata["type"] - _ = compiler_data.ir_runtime # ensure _ir_info is generated + if compiler_data.contract_path.suffix != ".vyi": + _ = compiler_data.ir_runtime # ensure _ir_info is generated abi = module_t.interface.to_toplevel_abi_dict() if compiler_data.show_gas_estimates: From 112c76f79ee84c82620854d316b66daed7e98f9c Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 11 Oct 2024 17:25:06 +0200 Subject: [PATCH 03/34] exclude some output formats when compiling interface --- vyper/compiler/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vyper/compiler/__init__.py b/vyper/compiler/__init__.py index 0345c24931..2360925386 100644 --- a/vyper/compiler/__init__.py +++ b/vyper/compiler/__init__.py @@ -46,6 +46,11 @@ "opcodes_runtime": output.build_opcodes_runtime_output, } +INTERFACE_OUTPUT_FORMATS = ["ast_dict", + "annotated_ast_dict", + "interface", + "external_interface", + "abi"] UNKNOWN_CONTRACT_NAME = "" @@ -121,6 +126,8 @@ def compile_from_file_input( for output_format in output_formats: if output_format not in OUTPUT_FORMATS: raise ValueError(f"Unsupported format type {repr(output_format)}") + elif file_input.resolved_path.suffix == ".vyi" and output_format not in INTERFACE_OUTPUT_FORMATS: + raise ValueError(f"Unsupported format for compiling interface: {repr(output_format)}") try: formatter = OUTPUT_FORMATS[output_format] ret[output_format] = formatter(compiler_data) From fc05efe39dc31bb564c18a41c1be162e5c7677c7 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 11 Oct 2024 17:26:05 +0200 Subject: [PATCH 04/34] add test for interface outputs --- .../cli/vyper_compile/test_compile_files.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 3856aa3362..a13cd0aa84 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -425,3 +425,29 @@ def test_archive_search_path(tmp_path_factory, make_file, chdir_tmp_path): used_dir = search_paths[-1].stem # either dir1 or dir2 assert output_bundle.used_search_paths == [".", "0/" + used_dir] + +def test_compile_interface_file(make_file): + interface = """ +@view +@external +def foo() -> String[1]: + ... + +@view +@external +def bar() -> String[1]: + ... + +@external +def baz() -> uint8: + ... + + """ + file = make_file("interface.vyi", interface) + compile_files([file], ["ast","annotated_ast","interface","external_interface","abi"]) + + with pytest.raises(ValueError): + compile_files([file],["bytecode"]) + + with pytest.raises(ValueError): + compile_files([file],["asm"]) \ No newline at end of file From e5fc9a77cb3f7507f6de3f8088d829e97420aba9 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 12 Oct 2024 08:48:04 +0200 Subject: [PATCH 05/34] iterate through all unsupported formats --- .../cli/vyper_compile/test_compile_files.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index a13cd0aa84..044a56ba42 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -446,8 +446,33 @@ def baz() -> uint8: file = make_file("interface.vyi", interface) compile_files([file], ["ast","annotated_ast","interface","external_interface","abi"]) - with pytest.raises(ValueError): - compile_files([file],["bytecode"]) - - with pytest.raises(ValueError): - compile_files([file],["asm"]) \ No newline at end of file + unallowed_formats = [ + "layout", + "devdoc", + "userdoc", + "archive", + "archive_b64", + "integrity", + "solc_json", + "bb", + "bb_runtime", + "cfg", + "cfg_runtime", + "ir", + "ir_runtime", + "ir_dict", + "ir_runtime_dict", + "method_identifiers", + "metadata", + "asm", + "source_map", + "source_map_runtime", + "bytecode", + "bytecode_runtime", + "blueprint_bytecode", + "opcodes", + "opcodes_runtime"] + + for f in unallowed_formats: + with pytest.raises(ValueError): + compile_files([file], [f]) \ No newline at end of file From 328f7fd8728d63c1760dcf3b44fc64a34acf1705 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 12 Oct 2024 09:13:09 +0200 Subject: [PATCH 06/34] tag modules with is_interface --- vyper/ast/nodes.py | 4 ++++ vyper/compiler/output.py | 2 +- vyper/compiler/phases.py | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index d3c721dbfb..809fdb5d8d 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -647,6 +647,10 @@ def to_dict(self): def source_sha256sum(self): return sha256sum(self.full_source_code) + @property + def is_interface(self): + return self.resolved_path.endswith(".vyi") + @contextlib.contextmanager def namespace(self): from vyper.semantics.namespace import get_namespace, override_global_namespace diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index a96c66089c..3c21d21146 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -254,7 +254,7 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict: def build_abi_output(compiler_data: CompilerData) -> list: module_t = compiler_data.annotated_vyper_module._metadata["type"] - if compiler_data.contract_path.suffix != ".vyi": + if not compiler_data.annotated_vyper_module.is_interface: _ = compiler_data.ir_runtime # ensure _ir_info is generated abi = module_t.interface.to_toplevel_abi_dict() diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 3e38b4aa1b..4e0c21721d 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -287,8 +287,7 @@ def generate_annotated_ast(vyper_module: vy_ast.Module, input_bundle: InputBundl vyper_module = copy.deepcopy(vyper_module) with input_bundle.search_path(Path(vyper_module.resolved_path).parent): # note: analyze_module does type inference on the AST - is_interface = vyper_module.resolved_path.endswith(".vyi") - analyze_module(vyper_module, input_bundle, is_interface=is_interface) + analyze_module(vyper_module, input_bundle, is_interface=vyper_module.is_interface) return vyper_module From 36c620c87e92c8eceff3c3bcda90d37bfb56f456 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sun, 13 Oct 2024 16:41:13 +0200 Subject: [PATCH 07/34] add is_interface tag to ModuleT --- vyper/ast/nodes.py | 4 ---- vyper/compiler/output.py | 2 +- vyper/compiler/phases.py | 3 ++- vyper/semantics/analysis/module.py | 1 + vyper/semantics/types/module.py | 1 + 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index 809fdb5d8d..d3c721dbfb 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -647,10 +647,6 @@ def to_dict(self): def source_sha256sum(self): return sha256sum(self.full_source_code) - @property - def is_interface(self): - return self.resolved_path.endswith(".vyi") - @contextlib.contextmanager def namespace(self): from vyper.semantics.namespace import get_namespace, override_global_namespace diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 3c21d21146..7961665680 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -254,7 +254,7 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict: def build_abi_output(compiler_data: CompilerData) -> list: module_t = compiler_data.annotated_vyper_module._metadata["type"] - if not compiler_data.annotated_vyper_module.is_interface: + if not module_t.is_interface: _ = compiler_data.ir_runtime # ensure _ir_info is generated abi = module_t.interface.to_toplevel_abi_dict() diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 4e0c21721d..3e38b4aa1b 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -287,7 +287,8 @@ def generate_annotated_ast(vyper_module: vy_ast.Module, input_bundle: InputBundl vyper_module = copy.deepcopy(vyper_module) with input_bundle.search_path(Path(vyper_module.resolved_path).parent): # note: analyze_module does type inference on the AST - analyze_module(vyper_module, input_bundle, is_interface=vyper_module.is_interface) + is_interface = vyper_module.resolved_path.endswith(".vyi") + analyze_module(vyper_module, input_bundle, is_interface=is_interface) return vyper_module diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 6816fbed98..6f01c97749 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -99,6 +99,7 @@ def _analyze_module_r( generate_public_variable_getters(module_ast) ret = ModuleT(module_ast) + ret.is_interface = is_interface module_ast._metadata["type"] = ret # if this is an interface, the function is already validated diff --git a/vyper/semantics/types/module.py b/vyper/semantics/types/module.py index ba72842c65..43a7c01032 100644 --- a/vyper/semantics/types/module.py +++ b/vyper/semantics/types/module.py @@ -298,6 +298,7 @@ def __init__(self, module: vy_ast.Module, name: Optional[str] = None): self._helper = VyperType() self._helper._id = self._id + self.is_interface = None for f in self.function_defs: # note: this checks for collisions From d181da1a1d5a351a4592e0be0b3f4214b863e944 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 14 Oct 2024 19:14:18 +0200 Subject: [PATCH 08/34] add is_interface to parse_to_ast_with_settings --- vyper/ast/nodes.py | 2 +- vyper/ast/parse.py | 2 ++ vyper/compiler/output.py | 2 +- vyper/compiler/phases.py | 4 ++-- vyper/semantics/analysis/module.py | 1 - vyper/semantics/types/module.py | 1 - 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index d3c721dbfb..f50e0f3dd2 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -638,7 +638,7 @@ class TopLevel(VyperNode): class Module(TopLevel): # metadata - __slots__ = ("path", "resolved_path", "source_id") + __slots__ = ("path", "resolved_path", "source_id", "is_interface") def to_dict(self): return dict(source_sha256sum=self.source_sha256sum, **super().to_dict()) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index d4569dd644..0bd2cde0e1 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -24,6 +24,7 @@ def parse_to_ast_with_settings( module_path: Optional[str] = None, resolved_path: Optional[str] = None, add_fn_node: Optional[str] = None, + is_interface: bool = False ) -> tuple[Settings, vy_ast.Module]: """ Parses a Vyper source string and generates basic Vyper AST nodes. @@ -86,6 +87,7 @@ def parse_to_ast_with_settings( # Convert to Vyper AST. module = vy_ast.get_node(py_ast) assert isinstance(module, vy_ast.Module) # mypy hint + module.is_interface = is_interface return settings, module diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 7961665680..3c21d21146 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -254,7 +254,7 @@ def build_method_identifiers_output(compiler_data: CompilerData) -> dict: def build_abi_output(compiler_data: CompilerData) -> list: module_t = compiler_data.annotated_vyper_module._metadata["type"] - if not module_t.is_interface: + if not compiler_data.annotated_vyper_module.is_interface: _ = compiler_data.ir_runtime # ensure _ir_info is generated abi = module_t.interface.to_toplevel_abi_dict() diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index 3e38b4aa1b..8ba6189ab0 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -116,6 +116,7 @@ def _generate_ast(self): self.source_id, module_path=self.contract_path.as_posix(), resolved_path=self.file_input.resolved_path.as_posix(), + is_interface=self.contract_path.suffix == ".vyi", ) if self.original_settings: @@ -287,8 +288,7 @@ def generate_annotated_ast(vyper_module: vy_ast.Module, input_bundle: InputBundl vyper_module = copy.deepcopy(vyper_module) with input_bundle.search_path(Path(vyper_module.resolved_path).parent): # note: analyze_module does type inference on the AST - is_interface = vyper_module.resolved_path.endswith(".vyi") - analyze_module(vyper_module, input_bundle, is_interface=is_interface) + analyze_module(vyper_module, input_bundle, is_interface=vyper_module.is_interface) return vyper_module diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 6f01c97749..6816fbed98 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -99,7 +99,6 @@ def _analyze_module_r( generate_public_variable_getters(module_ast) ret = ModuleT(module_ast) - ret.is_interface = is_interface module_ast._metadata["type"] = ret # if this is an interface, the function is already validated diff --git a/vyper/semantics/types/module.py b/vyper/semantics/types/module.py index 43a7c01032..ba72842c65 100644 --- a/vyper/semantics/types/module.py +++ b/vyper/semantics/types/module.py @@ -298,7 +298,6 @@ def __init__(self, module: vy_ast.Module, name: Optional[str] = None): self._helper = VyperType() self._helper._id = self._id - self.is_interface = None for f in self.function_defs: # note: this checks for collisions From 5d4e55b9f202b044f009c64805589e98d22b4ed0 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 14 Oct 2024 19:27:39 +0200 Subject: [PATCH 09/34] adjust tests --- tests/unit/ast/test_ast_dict.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/ast/test_ast_dict.py b/tests/unit/ast/test_ast_dict.py index c9d7248809..196b1e24e6 100644 --- a/tests/unit/ast/test_ast_dict.py +++ b/tests/unit/ast/test_ast_dict.py @@ -399,6 +399,7 @@ def foo(): "node_id": 0, "path": "main.vy", "source_id": 1, + "is_interface": False, "type": { "name": "main.vy", "type_decl_node": {"node_id": 0, "source_id": 1}, @@ -1175,6 +1176,7 @@ def foo(): "node_id": 0, "path": "lib1.vy", "source_id": 0, + "is_interface": False, "type": { "name": "lib1.vy", "type_decl_node": {"node_id": 0, "source_id": 0}, From 66410923ed20eb435540acfc84d3adb255be4211 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Mon, 14 Oct 2024 20:07:10 +0200 Subject: [PATCH 10/34] lint --- .../cli/vyper_compile/test_compile_files.py | 56 ++++++++++--------- vyper/ast/parse.py | 2 +- vyper/compiler/__init__.py | 21 ++++--- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 044a56ba42..371c172f32 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -426,6 +426,7 @@ def test_archive_search_path(tmp_path_factory, make_file, chdir_tmp_path): used_dir = search_paths[-1].stem # either dir1 or dir2 assert output_bundle.used_search_paths == [".", "0/" + used_dir] + def test_compile_interface_file(make_file): interface = """ @view @@ -444,35 +445,36 @@ def baz() -> uint8: """ file = make_file("interface.vyi", interface) - compile_files([file], ["ast","annotated_ast","interface","external_interface","abi"]) + compile_files([file], ["ast", "annotated_ast", "interface", "external_interface", "abi"]) unallowed_formats = [ - "layout", - "devdoc", - "userdoc", - "archive", - "archive_b64", - "integrity", - "solc_json", - "bb", - "bb_runtime", - "cfg", - "cfg_runtime", - "ir", - "ir_runtime", - "ir_dict", - "ir_runtime_dict", - "method_identifiers", - "metadata", - "asm", - "source_map", - "source_map_runtime", - "bytecode", - "bytecode_runtime", - "blueprint_bytecode", - "opcodes", - "opcodes_runtime"] + "layout", + "devdoc", + "userdoc", + "archive", + "archive_b64", + "integrity", + "solc_json", + "bb", + "bb_runtime", + "cfg", + "cfg_runtime", + "ir", + "ir_runtime", + "ir_dict", + "ir_runtime_dict", + "method_identifiers", + "metadata", + "asm", + "source_map", + "source_map_runtime", + "bytecode", + "bytecode_runtime", + "blueprint_bytecode", + "opcodes", + "opcodes_runtime", + ] for f in unallowed_formats: with pytest.raises(ValueError): - compile_files([file], [f]) \ No newline at end of file + compile_files([file], [f]) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index 0bd2cde0e1..fa67dc1c1b 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -24,7 +24,7 @@ def parse_to_ast_with_settings( module_path: Optional[str] = None, resolved_path: Optional[str] = None, add_fn_node: Optional[str] = None, - is_interface: bool = False + is_interface: bool = False, ) -> tuple[Settings, vy_ast.Module]: """ Parses a Vyper source string and generates basic Vyper AST nodes. diff --git a/vyper/compiler/__init__.py b/vyper/compiler/__init__.py index 2360925386..3a98717414 100644 --- a/vyper/compiler/__init__.py +++ b/vyper/compiler/__init__.py @@ -46,11 +46,13 @@ "opcodes_runtime": output.build_opcodes_runtime_output, } -INTERFACE_OUTPUT_FORMATS = ["ast_dict", - "annotated_ast_dict", - "interface", - "external_interface", - "abi"] +INTERFACE_OUTPUT_FORMATS = [ + "ast_dict", + "annotated_ast_dict", + "interface", + "external_interface", + "abi", +] UNKNOWN_CONTRACT_NAME = "" @@ -126,8 +128,13 @@ def compile_from_file_input( for output_format in output_formats: if output_format not in OUTPUT_FORMATS: raise ValueError(f"Unsupported format type {repr(output_format)}") - elif file_input.resolved_path.suffix == ".vyi" and output_format not in INTERFACE_OUTPUT_FORMATS: - raise ValueError(f"Unsupported format for compiling interface: {repr(output_format)}") + elif ( + file_input.resolved_path.suffix == ".vyi" + and output_format not in INTERFACE_OUTPUT_FORMATS + ): + raise ValueError( + f"Unsupported format for compiling interface: {repr(output_format)}" + ) try: formatter = OUTPUT_FORMATS[output_format] ret[output_format] = formatter(compiler_data) From afd8f8ef69d3de1d8623524d781aaa72ccfa0e9d Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Tue, 15 Oct 2024 09:02:38 +0200 Subject: [PATCH 11/34] adjust solution due to merge --- vyper/compiler/phases.py | 1 + vyper/semantics/analysis/module.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index d9b6b13b48..cee561f78f 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -117,6 +117,7 @@ def _generate_ast(self): self.source_id, module_path=self.contract_path.as_posix(), resolved_path=self.file_input.resolved_path.as_posix(), + is_interface=self.contract_path.suffix == ".vyi", ) if self.original_settings: diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index 8a2beb61e6..5416926c42 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -53,7 +53,7 @@ def analyze_module(module_ast: vy_ast.Module) -> ModuleT: add all module-level objects to the namespace, type-check/validate semantics and annotate with type and analysis info """ - return _analyze_module_r(module_ast) + return _analyze_module_r(module_ast, module_ast.is_interface) def _analyze_module_r(module_ast: vy_ast.Module, is_interface: bool = False): From 8048d4f19a2305152d22673f077e4b2ba6b36cfc Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 15 Oct 2024 07:44:26 -0400 Subject: [PATCH 12/34] reduce a multiline expression --- vyper/compiler/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vyper/compiler/__init__.py b/vyper/compiler/__init__.py index 3a98717414..730c67563c 100644 --- a/vyper/compiler/__init__.py +++ b/vyper/compiler/__init__.py @@ -124,17 +124,18 @@ def compile_from_file_input( ) ret = {} + with anchor_settings(compiler_data.settings): for output_format in output_formats: if output_format not in OUTPUT_FORMATS: raise ValueError(f"Unsupported format type {repr(output_format)}") - elif ( - file_input.resolved_path.suffix == ".vyi" - and output_format not in INTERFACE_OUTPUT_FORMATS - ): + + is_vyi = file_input.resolved_path.suffix == ".vyi" + if is_vyi and output_format not in INTERFACE_OUTPUT_FORMATS: raise ValueError( f"Unsupported format for compiling interface: {repr(output_format)}" ) + try: formatter = OUTPUT_FORMATS[output_format] ret[output_format] = formatter(compiler_data) From 2651d896a9228a0978b8861eb5aebaabc47fa55e Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 15 Oct 2024 07:45:49 -0400 Subject: [PATCH 13/34] fix mypy --- vyper/ast/nodes.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/vyper/ast/nodes.pyi b/vyper/ast/nodes.pyi index 783764271d..b00354c03a 100644 --- a/vyper/ast/nodes.pyi +++ b/vyper/ast/nodes.pyi @@ -71,6 +71,7 @@ class Module(TopLevel): path: str = ... resolved_path: str = ... source_id: int = ... + is_interface: bool = ... def namespace(self) -> Any: ... # context manager class FunctionDef(TopLevel): From 1134c3a5fadc6786a752b9fde57048a9e114290a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 15 Oct 2024 07:50:34 -0400 Subject: [PATCH 14/34] style: factor out an expression --- vyper/compiler/phases.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index cee561f78f..29c5264ebb 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -112,12 +112,14 @@ def contract_path(self): @cached_property def _generate_ast(self): + is_vyi = self.contract_path.suffix == ".vyi" + settings, ast = vy_ast.parse_to_ast_with_settings( self.source_code, self.source_id, module_path=self.contract_path.as_posix(), resolved_path=self.file_input.resolved_path.as_posix(), - is_interface=self.contract_path.suffix == ".vyi", + is_interface=is_vyi, ) if self.original_settings: From 324b598f8e35fa0bb6f37462ab12624268736d0c Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 25 Oct 2024 10:50:29 +0200 Subject: [PATCH 15/34] add flags into interface output --- vyper/compiler/output.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 5d3ee633ab..ed7d39b083 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -136,6 +136,14 @@ def build_interface_output(compiler_data: CompilerData) -> str: out += f" {member_name}: {member_type}\n" out += "\n\n" + if len(interface.flags) > 0: + out += "# Flags\n\n" + for flag in interface.flags.values(): + out += f"flag {flag.name}:\n" + for flag_value in flag._flag_members: + out += f" {flag_value}\n" + out += "\n\n" + if len(interface.events) > 0: out += "# Events\n\n" for event in interface.events.values(): From 50692a1a908b9b52f43d4bdaf044dff843269045 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 25 Oct 2024 10:54:08 +0200 Subject: [PATCH 16/34] add test for presence of flags in interface output --- tests/functional/codegen/test_interfaces.py | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 8887bf07cb..877a43564d 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -774,3 +774,38 @@ def foo(s: MyStruct) -> MyStruct: assert "b: uint256" in out assert "struct Voter:" in out assert "voted: bool" in out + +def test_interface_with_flags(): + code = """ +struct MyStruct: + a: address + +flag Foo: + BOO + MOO + POO + +event Transfer: + sender: indexed(address) + +@external +def bar(): + pass +flag BAR: + BIZ + BAZ + BOO + +@external +@view +def foo(s: MyStruct) -> MyStruct: + return s + """ + + out = compile_code(code, contract_path="code.vy", output_formats=["interface"])["interface"] + + assert "# Flags" in out + assert "flag Foo:" in out + assert "flag BAR" in out + assert "BOO" in out + assert "MOO" in out From fcfc2ec9fd7489b65b13d7d6c0f67821fbd1a6fb Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 25 Oct 2024 10:55:25 +0200 Subject: [PATCH 17/34] lint --- tests/functional/codegen/test_interfaces.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 877a43564d..900f5690cc 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -775,6 +775,7 @@ def foo(s: MyStruct) -> MyStruct: assert "struct Voter:" in out assert "voted: bool" in out + def test_interface_with_flags(): code = """ struct MyStruct: From 60dddd443e4bbc10c81daef62bf0394700b50e57 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Fri, 25 Oct 2024 11:28:37 +0200 Subject: [PATCH 18/34] capitalize the first letter but leave the rest the same --- vyper/compiler/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index ed7d39b083..6f6bd6f50b 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -110,7 +110,7 @@ def build_external_interface_output(compiler_data: CompilerData) -> str: stem = PurePath(compiler_data.contract_path).stem # capitalize words separated by '_' # ex: test_interface.vy -> TestInterface - name = "".join([x.capitalize() for x in stem.split("_")]) + name = "".join([x[0].upper() + x[1:] for x in stem.split("_")]) out = f"\n# External Interfaces\ninterface {name}:\n" for func in interface.functions.values(): From 3bf93893cb688a116c42d476e07a62ea730a7abe Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Tue, 29 Oct 2024 12:50:02 +0100 Subject: [PATCH 19/34] fix flake8 errors --- tests/functional/codegen/test_interfaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 900f5690cc..76a044e4b6 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -780,7 +780,7 @@ def test_interface_with_flags(): code = """ struct MyStruct: a: address - + flag Foo: BOO MOO From 5d954d83c66166fd2ff54756eeba7f8eb7049350 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Thu, 7 Nov 2024 08:53:59 +0000 Subject: [PATCH 20/34] remove duplicate list --- tests/unit/cli/vyper_compile/test_compile_files.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 371c172f32..f04cd9ab72 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -7,6 +7,7 @@ from vyper.cli.vyper_compile import compile_files from vyper.cli.vyper_json import compile_json +from vyper.compiler import INTERFACE_OUTPUT_FORMATS from vyper.compiler.input_bundle import FilesystemInputBundle from vyper.compiler.output_bundle import OutputBundle from vyper.compiler.phases import CompilerData @@ -445,7 +446,7 @@ def baz() -> uint8: """ file = make_file("interface.vyi", interface) - compile_files([file], ["ast", "annotated_ast", "interface", "external_interface", "abi"]) + compile_files([file], INTERFACE_OUTPUT_FORMATS) unallowed_formats = [ "layout", From a21dc187661d4738f9137e0c9434f90d536fe549 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 7 Dec 2024 15:27:07 +0100 Subject: [PATCH 21/34] handle edgecases of filenames --- tests/functional/codegen/test_interfaces.py | 18 ++++++++++++++++++ vyper/compiler/output.py | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 76a044e4b6..24b8fe4323 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -810,3 +810,21 @@ def foo(s: MyStruct) -> MyStruct: assert "flag BAR" in out assert "BOO" in out assert "MOO" in out + + +def test_external_interface_names(): + code = """ +@external +def foo(): + ... + """ + + compile_code(code, contract_path="test__test.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="test__t.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="t__test.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="t__t.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="t_t.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="test_test.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="t_test.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="test_t.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="_test_t__t_tt_.vyi", output_formats=["external_interface"]) diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index 6f6bd6f50b..f6e68c03ea 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -108,9 +108,15 @@ def build_integrity(compiler_data: CompilerData) -> str: def build_external_interface_output(compiler_data: CompilerData) -> str: interface = compiler_data.annotated_vyper_module._metadata["type"].interface stem = PurePath(compiler_data.contract_path).stem + # capitalize words separated by '_' # ex: test_interface.vy -> TestInterface - name = "".join([x[0].upper() + x[1:] for x in stem.split("_")]) + def capitalize_part(part): + if len(part) > 0: # safe even if 1 cause [1:] will be just empty string + return part[0].upper() + part[1:] + return "" + + name = "".join([capitalize_part(x) for x in stem.split("_")]) out = f"\n# External Interfaces\ninterface {name}:\n" for func in interface.functions.values(): From af655be277d01ce7d6a2d0d05e0e10278bbee24f Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 7 Dec 2024 15:42:18 +0100 Subject: [PATCH 22/34] add str function for FlagT --- vyper/semantics/types/user.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 73fa4878c7..d01ab23299 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -77,6 +77,9 @@ def get_type_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType": self._helper.get_member(key, node) return self + def __str__(self): + return f"{self.name}" + def __repr__(self): arg_types = ",".join(repr(a) for a in self._flag_members) return f"flag {self.name}({arg_types})" From bef8725adad8a304df47482ad727b2c83eb55d62 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 7 Dec 2024 15:49:39 +0100 Subject: [PATCH 23/34] test function with flag as return type --- tests/functional/codegen/test_interfaces.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 24b8fe4323..f8b2d64cdd 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -828,3 +828,19 @@ def foo(): compile_code(code, contract_path="t_test.vyi", output_formats=["external_interface"]) compile_code(code, contract_path="test_t.vyi", output_formats=["external_interface"]) compile_code(code, contract_path="_test_t__t_tt_.vyi", output_formats=["external_interface"]) + + +def test_external_interface_with_flag(): + code = """ +flag Foo: + Blah + +@external +def foo() -> Foo: + ... + """ + + out = compile_code(code, contract_path="test__test.vyi", output_formats=["external_interface"])[ + "external_interface" + ] + assert "-> Foo:" in out From 4c476ad27fddaf1a1b55f8fbdcd311b76bf9b330 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 7 Dec 2024 16:08:28 +0100 Subject: [PATCH 24/34] take file_input from compiler_data after merge --- vyper/compiler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/compiler/__init__.py b/vyper/compiler/__init__.py index 6648da6214..57bd2f4096 100644 --- a/vyper/compiler/__init__.py +++ b/vyper/compiler/__init__.py @@ -134,7 +134,7 @@ def outputs_from_compiler_data( if output_format not in OUTPUT_FORMATS: raise ValueError(f"Unsupported format type {repr(output_format)}") - is_vyi = file_input.resolved_path.suffix == ".vyi" + is_vyi = compiler_data.file_input.resolved_path.suffix == ".vyi" if is_vyi and output_format not in INTERFACE_OUTPUT_FORMATS: raise ValueError( f"Unsupported format for compiling interface: {repr(output_format)}" From 3bc7ef8eea599c25561745e0d2f22a8114d541b4 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Thu, 12 Dec 2024 14:46:37 +0100 Subject: [PATCH 25/34] use the OUTPUT_FORMATS instead of listing all options --- tests/unit/cli/vyper_compile/test_compile_files.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index f04cd9ab72..78375780f5 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -7,7 +7,7 @@ from vyper.cli.vyper_compile import compile_files from vyper.cli.vyper_json import compile_json -from vyper.compiler import INTERFACE_OUTPUT_FORMATS +from vyper.compiler import INTERFACE_OUTPUT_FORMATS, OUTPUT_FORMATS from vyper.compiler.input_bundle import FilesystemInputBundle from vyper.compiler.output_bundle import OutputBundle from vyper.compiler.phases import CompilerData @@ -476,6 +476,8 @@ def baz() -> uint8: "opcodes_runtime", ] - for f in unallowed_formats: + for f in OUTPUT_FORMATS: + if f in INTERFACE_OUTPUT_FORMATS: + continue with pytest.raises(ValueError): compile_files([file], [f]) From d851c733d267b6f89b53628087d8313ae121b3bb Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Thu, 12 Dec 2024 14:53:10 +0100 Subject: [PATCH 26/34] replace capitilising by a cleaner solution --- tests/functional/codegen/test_interfaces.py | 1 + vyper/compiler/output.py | 9 +-------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 1a43957b43..d2751884ac 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -917,6 +917,7 @@ def foo(): compile_code(code, contract_path="t_test.vyi", output_formats=["external_interface"]) compile_code(code, contract_path="test_t.vyi", output_formats=["external_interface"]) compile_code(code, contract_path="_test_t__t_tt_.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path="foo_bar_baz.vyi", output_formats=["external_interface"]) def test_external_interface_with_flag(): diff --git a/vyper/compiler/output.py b/vyper/compiler/output.py index defb10e9d9..c8818c1972 100644 --- a/vyper/compiler/output.py +++ b/vyper/compiler/output.py @@ -109,14 +109,7 @@ def build_external_interface_output(compiler_data: CompilerData) -> str: interface = compiler_data.annotated_vyper_module._metadata["type"].interface stem = PurePath(compiler_data.contract_path).stem - # capitalize words separated by '_' - # ex: test_interface.vy -> TestInterface - def capitalize_part(part): - if len(part) > 0: # safe even if 1 cause [1:] will be just empty string - return part[0].upper() + part[1:] - return "" - - name = "".join([capitalize_part(x) for x in stem.split("_")]) + name = stem.title().replace("_", "") out = f"\n# External Interfaces\ninterface {name}:\n" for func in interface.functions.values(): From a3928984c1e03f8b3c599ef5c3f5387845068b90 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Thu, 12 Dec 2024 15:03:30 +0100 Subject: [PATCH 27/34] remove unused list --- .../cli/vyper_compile/test_compile_files.py | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 78375780f5..94adfcafe0 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -448,34 +448,6 @@ def baz() -> uint8: file = make_file("interface.vyi", interface) compile_files([file], INTERFACE_OUTPUT_FORMATS) - unallowed_formats = [ - "layout", - "devdoc", - "userdoc", - "archive", - "archive_b64", - "integrity", - "solc_json", - "bb", - "bb_runtime", - "cfg", - "cfg_runtime", - "ir", - "ir_runtime", - "ir_dict", - "ir_runtime_dict", - "method_identifiers", - "metadata", - "asm", - "source_map", - "source_map_runtime", - "bytecode", - "bytecode_runtime", - "blueprint_bytecode", - "opcodes", - "opcodes_runtime", - ] - for f in OUTPUT_FORMATS: if f in INTERFACE_OUTPUT_FORMATS: continue From e46ccb7dccb48fd57e3096960750fb82d8f41a26 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 13 Dec 2024 10:59:43 -0500 Subject: [PATCH 28/34] remove repeated code --- tests/functional/codegen/test_interfaces.py | 28 +++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index d2751884ac..6b85833817 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -901,23 +901,29 @@ def foo(s: MyStruct) -> MyStruct: assert "MOO" in out -def test_external_interface_names(): +vyi_filenames = [ + "test__test.vyi", + "test__t.vyi", + "t__test.vyi", + "t__t.vyi", + "t_t.vyi", + "test_test.vyi", + "t_test.vyi", + "test_t.vyi", + "_test_t__t_tt_.vyi", + "foo_bar_baz.vyi", +] + + +@pytest.mark.parametrize("vyi_filename", vyi_filenames) +def test_external_interface_names(vyi_filename): code = """ @external def foo(): ... """ - compile_code(code, contract_path="test__test.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="test__t.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="t__test.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="t__t.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="t_t.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="test_test.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="t_test.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="test_t.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="_test_t__t_tt_.vyi", output_formats=["external_interface"]) - compile_code(code, contract_path="foo_bar_baz.vyi", output_formats=["external_interface"]) + compile_code(code, contract_path=vyi_filename, output_formats=["external_interface"]) def test_external_interface_with_flag(): From bce2a08a45f0bb70fba0d985ec6dd90e289d2fbf Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sun, 15 Dec 2024 10:50:26 +0100 Subject: [PATCH 29/34] test compilation round trip --- tests/functional/codegen/test_interfaces.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 6b85833817..b6cb8c0d68 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -900,6 +900,8 @@ def foo(s: MyStruct) -> MyStruct: assert "BOO" in out assert "MOO" in out + compile_code(out, contract_path="code.vyi", output_formats=["interface"]) + vyi_filenames = [ "test__test.vyi", @@ -940,3 +942,19 @@ def foo() -> Foo: "external_interface" ] assert "-> Foo:" in out + + +def test_external_interface_compiles_again(): + code = """ +@external +def foo() -> uint256: + ... +@external +def bar(a:int32) -> uint256: + ... + """ + + out = compile_code(code, contract_path="test.vyi", output_formats=["external_interface"])[ + "external_interface" + ] + compile_code(out, contract_path="test.vyi", output_formats=["external_interface"]) From e37f4f75a28a991d303f08c07d3be6fd24db9cef Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sun, 15 Dec 2024 10:51:11 +0100 Subject: [PATCH 30/34] add comment --- tests/unit/cli/vyper_compile/test_compile_files.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 94adfcafe0..d8d9e56777 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -448,6 +448,7 @@ def baz() -> uint8: file = make_file("interface.vyi", interface) compile_files([file], INTERFACE_OUTPUT_FORMATS) + # check unallowed output formats for f in OUTPUT_FORMATS: if f in INTERFACE_OUTPUT_FORMATS: continue From 53b4626cbafaa9660c3c04a173cceede3b2fbd5a Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sun, 15 Dec 2024 10:52:26 +0100 Subject: [PATCH 31/34] test weird interface name --- tests/functional/codegen/test_interfaces.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index b6cb8c0d68..6a9c019d02 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -958,3 +958,11 @@ def bar(a:int32) -> uint256: "external_interface" ] compile_code(out, contract_path="test.vyi", output_formats=["external_interface"]) + + +@pytest.mark.xfail +def test_weird_interface_name(): + out = compile_code("", contract_path="_.vyi", output_formats=["external_interface"])[ + "external_interface" + ] + assert "interface _:" in out From cea1f217e155128d2a5612d36ee545b6f261db65 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sun, 15 Dec 2024 11:24:26 +0100 Subject: [PATCH 32/34] add comment --- vyper/ast/parse.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index ead6e43b2a..7d4e4ba736 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -47,6 +47,9 @@ def parse_to_ast_with_settings( resolved_path: str, optional The resolved path of the source code Corresponds to FileInput.resolved_path + is_interface: bool + Indicates whether the source code should + be parsed as an interface file. Returns ------- From be7318bb104a2da46ee5f832df5422245a833bbf Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Wed, 18 Dec 2024 19:04:52 +0100 Subject: [PATCH 33/34] add parameter to inner function after merge with master --- vyper/ast/parse.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index 4427a5bf2f..423b37721a 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -27,7 +27,7 @@ def parse_to_ast_with_settings( ) -> tuple[Settings, vy_ast.Module]: try: return _parse_to_ast_with_settings( - vyper_source, source_id, module_path, resolved_path, add_fn_node + vyper_source, source_id, module_path, resolved_path, add_fn_node, is_interface ) except SyntaxException as e: e.resolved_path = resolved_path @@ -40,6 +40,7 @@ def _parse_to_ast_with_settings( module_path: Optional[str] = None, resolved_path: Optional[str] = None, add_fn_node: Optional[str] = None, + is_interface: bool = False, ) -> tuple[Settings, vy_ast.Module]: """ Parses a Vyper source string and generates basic Vyper AST nodes. From 37666bc5012f556729ce5c115934c82c967123fc Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Thu, 26 Dec 2024 09:55:52 +0100 Subject: [PATCH 34/34] explain test in comment --- tests/functional/codegen/test_interfaces.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/codegen/test_interfaces.py b/tests/functional/codegen/test_interfaces.py index 3af25a62d1..e0b59ff668 100644 --- a/tests/functional/codegen/test_interfaces.py +++ b/tests/functional/codegen/test_interfaces.py @@ -975,6 +975,8 @@ def bar(a:int32) -> uint256: @pytest.mark.xfail def test_weird_interface_name(): + # based on comment https://github.com/vyperlang/vyper/pull/4290#discussion_r1884137428 + # we replace "_" for "" which results in an interface without name out = compile_code("", contract_path="_.vyi", output_formats=["external_interface"])[ "external_interface" ]