Skip to content

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

Open
sandbubbles wants to merge 10 commits intovyperlang:masterfrom
sandbubbles:fix/unnecessary-interface-paths
Open

fix[ux]: shorten interface name in error messages#4359
sandbubbles wants to merge 10 commits intovyperlang:masterfrom
sandbubbles:fix/unnecessary-interface-paths

Conversation

@sandbubbles
Copy link
Copy Markdown
Contributor

@sandbubbles sandbubbles commented Nov 13, 2024

What I did

Change the representation of interfaces in errors to a name instead of a path. Fix #4237.
Edit: remove reference to #4299.

How I did it

Use only a part of _id as the interface's string representation and use it when printing signature.

How to verify it

Test that the interface either shows as name or interface name.

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->


def __repr__(self):
return f"interface {self._id}"
return f"interface {Path(self._id).stem}"
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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

@charles-cooper charles-cooper changed the title fix[ux]: shorten interface string from path to name fix[ux]: shorten interface name in error messages Nov 23, 2024

def __str__(self):
return self._id
return Path(self._id).stem
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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 only in one of the two issues #4237 or #4237?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, best to show the alias when calling __str__ if it comes from an import, and the InterfaceDef.name if it comes from an InterfaceDef. i looked into this today, and it doesn't seem so trivial to back out the alias once you are already in InterfaceT though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

confirming with a test:

import lib1
implements: lib1.__interface__
from ethereum.ercs import IERC20 as B

@external
def foobar(token: B):
    pass

This will raise with:

vyper.exceptions.InterfaceViolation: Contract does not implement all interface functions: foobar(IERC20)

@charles-cooper charles-cooper added the release - must release blocker label Mar 17, 2025
@cyberthirst cyberthirst added this to the v0.4.2 milestone Mar 17, 2025
@cyberthirst
Copy link
Copy Markdown
Collaborator

note that if we have a contract like

from ethereum.ercs import IERC20 as B

@external
def foobar(token: B):
    pass

and do -f interface, we'll get:

# Functions

@external
def foobar(token: IERC20):
    ...

The type definition is missing, so is the import. And now we don't even show the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release - must release blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display of interfaces in errors show full path

3 participants