Skip to content

Commit

Permalink
fix empty list check
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Apr 17, 2022
1 parent 683ef86 commit 14dd0da
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions vyper/semantics/validation/levenshtein_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ def get_levenshtein_error_suggestions(key: str, namespace: Dict[str, Any], thres
return ""

distances = sorted([(i, levenshtein_norm(key, i)) for i in namespace], key=lambda k: k[1])
min_levenshtein_val = distances[0][1]
if len(distances) > 0 and min_levenshtein_val <= threshold:
if distances[1][1] == min_levenshtein_val:
if len(distances) > 0 and distances[0][1] <= threshold:
if len(distances) >= 2 and distances[0][1] == distances[1][1]:

This comment has been minimized.

Copy link
@charles-cooper

charles-cooper Apr 17, 2022

Member

i think we do not need to check that the top two distances are equal, instead we only require that distances[1][1] is also <= threshold.

return f"Did you mean '{distances[0][0]}' or '{distances[1][0]}'?"
else:
return f"Did you mean '{distances[0][0]}'?"
Expand Down

0 comments on commit 14dd0da

Please sign in to comment.