Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[ux]: shorten interface name in error messages #4359

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/functional/syntax/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,43 @@ 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(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"]
2 changes: 1 addition & 1 deletion vyper/semantics/types/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion vyper/semantics/types/module.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -79,7 +80,7 @@ def abi_type(self) -> ABIType:
return ABI_Address()

def __str__(self):
return self._id
return Path(self._id).stem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the type is aliased? e.g.

from ethereum.ercs import IERC20 as BROWNBEAR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that would show the ierc20

Copy link
Collaborator Author

@sandbubbles sandbubbles Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want it to show the alias when calling __str__? Or in one of the two issues #4237 or #4237?


def __repr__(self):
return f"interface {self._id}"
Expand Down
Loading