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 3 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(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"]
5 changes: 3 additions & 2 deletions 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,10 +80,10 @@ 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}"
return f"interface {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.

i think we want to change the str implementation, but not repr -- repr should attempt to be injective back to interfaces

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i changed _pp_signature to use str, i think that should be okay cause its only used for error messages


def _try_fold(self, node):
if len(node.args) != 1:
Expand Down
Loading