From 8fa330595442ec1110415566c89c39c18577b000 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Wed, 13 Nov 2024 10:47:27 +0000 Subject: [PATCH 1/5] shorten interface string from path to name only --- vyper/semantics/types/module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vyper/semantics/types/module.py b/vyper/semantics/types/module.py index dabeaf21b6..bd65558a21 100644 --- a/vyper/semantics/types/module.py +++ b/vyper/semantics/types/module.py @@ -1,4 +1,5 @@ from functools import cached_property +from pathlib import Path from typing import TYPE_CHECKING, Optional from vyper import ast as vy_ast @@ -79,10 +80,10 @@ def abi_type(self) -> ABIType: return ABI_Address() def __str__(self): - return self._id + return Path(self._id).stem def __repr__(self): - return f"interface {self._id}" + return f"interface {Path(self._id).stem}" def _try_fold(self, node): if len(node.args) != 1: From 97c7d02e70b01c11f5bbadb9a886a65b79271685 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Wed, 13 Nov 2024 11:09:22 +0000 Subject: [PATCH 2/5] test InterfaceViolation does not print full interface path --- tests/functional/syntax/test_interfaces.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index 86ea4bcfd0..8540239cda 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -571,3 +571,31 @@ def bar(): compiler.compile_code(code, input_bundle=input_bundle) assert e.value.message == "Contract does not implement all interface functions: bar(), foobar()" + + +def test_interface_name_in_signature_is_short(make_input_bundle): + foo = """ +from ethereum.ercs import IERC20 + +def foobar(token: IERC20): + ... + """ + code = """ +from ethereum.ercs import IERC20 +import foo as Foo +implements: Foo + +@internal +def foobar(token: IERC20): + pass + """ + + input_bundle = make_input_bundle({"foo.vyi": foo}) + + with pytest.raises(InterfaceViolation) as e: + compiler.compile_code(code, input_bundle=input_bundle) + + assert ( + e.value.message + == "Contract does not implement all interface functions: foobar(interface IERC20)" + ) From e93853e9c2d1c403e2f5fb05a2674db14c19b43c Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Wed, 13 Nov 2024 11:29:56 +0000 Subject: [PATCH 3/5] test that "-f interface" outputs short interface names --- tests/functional/syntax/test_interfaces.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index 8540239cda..9af15b71f8 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -599,3 +599,15 @@ def foobar(token: IERC20): e.value.message == "Contract does not implement all interface functions: foobar(interface IERC20)" ) + + +def test_interface_name_in_output_is_short(make_input_bundle): + code = """ +from ethereum.ercs import IERC20 +@external +def test(input: IERC20): + pass + """ + out = compiler.compile_code(code, output_formats=["interface"]) + + assert "def test(input: IERC20):" in out["interface"] From 9ead96f857ce57313b607c4ca49793b668904acf Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 23 Nov 2024 11:39:23 +0000 Subject: [PATCH 4/5] revert __repr__ back to how it was --- vyper/semantics/types/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vyper/semantics/types/module.py b/vyper/semantics/types/module.py index bd65558a21..9ea4f0c467 100644 --- a/vyper/semantics/types/module.py +++ b/vyper/semantics/types/module.py @@ -83,7 +83,7 @@ def __str__(self): return Path(self._id).stem def __repr__(self): - return f"interface {Path(self._id).stem}" + return f"interface {self._id}" def _try_fold(self, node): if len(node.args) != 1: From 8821f01a669ae4dbd597482e10c16bf8b01766e3 Mon Sep 17 00:00:00 2001 From: Sand Bubbles Date: Sat, 23 Nov 2024 11:40:21 +0000 Subject: [PATCH 5/5] make _pp_signature use str not repr --- tests/functional/syntax/test_interfaces.py | 2 +- vyper/semantics/types/function.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/syntax/test_interfaces.py b/tests/functional/syntax/test_interfaces.py index 9af15b71f8..a693856f1d 100644 --- a/tests/functional/syntax/test_interfaces.py +++ b/tests/functional/syntax/test_interfaces.py @@ -597,7 +597,7 @@ def foobar(token: IERC20): assert ( e.value.message - == "Contract does not implement all interface functions: foobar(interface IERC20)" + == "Contract does not implement all interface functions: foobar(IERC20)" ) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 7a56b01281..ff078b722b 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -209,7 +209,7 @@ def __str__(self): @cached_property def _pp_signature(self): - ret = ",".join(repr(arg.typ) for arg in self.arguments) + ret = ",".join(str(arg.typ) for arg in self.arguments) return f"{self.name}({ret})" # override parent implementation. function type equality does not