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]: empty hint #4351

Open
wants to merge 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ def foo():

@pytest.mark.parametrize("bad_code", fail_list)
def test_undeclared_def_exception(bad_code):
with pytest.raises(UndeclaredDefinition):
with pytest.raises(UndeclaredDefinition) as e:
compiler.compile_code(bad_code)
assert "(hint: )" not in str(e.value)
15 changes: 15 additions & 0 deletions tests/functional/syntax/exceptions/test_unknown_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from vyper import compiler
from vyper.exceptions import UnknownType


def test_unknown_type_exception():
code = """
@internal
def foobar(token: IERC20):
pass
"""
with pytest.raises(UnknownType) as e:
compiler.compile_code(code)
assert "(hint: )" not in str(e.value)
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/levenshtein_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_levenshtein_error_suggestions(*args, **kwargs) -> Callable:

def _get_levenshtein_error_suggestions(
key: str, namespace: dict[str, Any], threshold: float
) -> str:
) -> str | None:
"""
Generate an error message snippet for the suggested closest values in the provided namespace
with the shortest normalized Levenshtein distance from the given key if that distance
Expand All @@ -99,12 +99,12 @@ def _get_levenshtein_error_suggestions(
or an empty string.
"""

if key is None or key == "":
return ""
if not key:
return None

distances = sorted([(i, levenshtein_norm(key, i)) for i in namespace], key=lambda k: k[1])
if len(distances) > 0 and distances[0][1] <= threshold:
if len(distances) > 1 and distances[1][1] <= threshold:
return f"Did you mean '{distances[0][0]}', or maybe '{distances[1][0]}'?"
return f"Did you mean '{distances[0][0]}'?"
return ""
return None
Loading