diff --git a/tests/functional/syntax/exceptions/test_undeclared_definition.py b/tests/functional/syntax/exceptions/test_undeclared_definition.py index f90aa4137b..5786b37b1f 100644 --- a/tests/functional/syntax/exceptions/test_undeclared_definition.py +++ b/tests/functional/syntax/exceptions/test_undeclared_definition.py @@ -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) diff --git a/tests/functional/syntax/exceptions/test_unknown_type.py b/tests/functional/syntax/exceptions/test_unknown_type.py new file mode 100644 index 0000000000..cd8866d5cb --- /dev/null +++ b/tests/functional/syntax/exceptions/test_unknown_type.py @@ -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) diff --git a/vyper/semantics/analysis/levenshtein_utils.py b/vyper/semantics/analysis/levenshtein_utils.py index fc6e497d43..ac4fe4fab3 100644 --- a/vyper/semantics/analysis/levenshtein_utils.py +++ b/vyper/semantics/analysis/levenshtein_utils.py @@ -1,4 +1,4 @@ -from typing import Any, Callable +from typing import Any, Callable, Optional def levenshtein_norm(source: str, target: str) -> float: @@ -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: +) -> Optional[str]: """ 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 @@ -100,11 +100,11 @@ def _get_levenshtein_error_suggestions( """ if key is None or key == "": - return "" + 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