Skip to content

Commit bcee123

Browse files
committed
add suggestions to misspelled tendency keywords
1 parent 7a6ff7f commit bcee123

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

waveform_editor/annotations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def add_yaml_error(self, error):
4444
else:
4545
self.add(0, f"Unknown YAML error: {error}")
4646

47-
def create_suggestion(self, match, list):
47+
def suggest(self, word_to_match, possible_matches):
4848
suggestion = ""
49-
close_matches = difflib.get_close_matches(match, list, n=1)
49+
close_matches = difflib.get_close_matches(word_to_match, possible_matches, n=1)
5050
if close_matches:
51-
suggestion = f"Did you mean {close_matches[0]!r}?"
51+
suggestion = f"{close_matches[0]!r}"
5252

5353
return suggestion
5454

waveform_editor/tendencies/base.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,26 @@ def _check_for_unknown_kwargs(self, kwargs):
211211
unknown_kwargs.append(key.replace("user_", ""))
212212
del kwargs[key]
213213
if unknown_kwargs:
214+
# Remove the user_ part of the param names to match suggestion
215+
params_list = [word.replace("user_", "") for word in list(self.param)]
214216
if len(unknown_kwargs) == 1:
217+
suggestion = self.annotations.suggest(unknown_kwargs[0], params_list)
215218
error_msg = (
216-
f"Unknown keyword passed: {', '.join(unknown_kwargs)}",
217-
" it will be ignored.",
219+
f"Unknown keyword passed: {unknown_kwargs[0]!r}. "
220+
f"Did you mean {suggestion}?\n"
221+
"This keyword will be ignored."
218222
)
219223
else:
224+
suggestions = []
225+
for unknown_kwarg in unknown_kwargs:
226+
suggestions.append(
227+
self.annotations.suggest(unknown_kwarg, params_list)
228+
)
220229
error_msg = (
221-
f"Multiple unknown keywords passed: {', '.join(unknown_kwargs)}",
222-
" they will be ignored.",
230+
"Multiple unknown keywords passed: "
231+
f"{', '.join(repr(k) for k in unknown_kwargs)}.\n"
232+
f"Did you mean {', '.join(suggestions)}?\n"
233+
"These keywords will be ignored.",
223234
)
224235

225236
self.annotations.add(line_number, error_msg, is_warning=True)

waveform_editor/waveform.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,12 @@ def _handle_tendency(self, entry):
137137
return tendency
138138
else:
139139
line_number = entry.pop("line_number")
140-
141-
suggestions = ""
142-
close_matches = difflib.get_close_matches(
143-
tendency_type, tendency_map.keys(), n=1
144-
)
145-
if close_matches:
146-
suggestions = f"Did you mean {close_matches[0]!r}?"
140+
suggestion = self.annotations.suggest(tendency_type, tendency_map.keys())
147141

148142
error_msg = (
149-
f"Unsupported tendency type: {tendency_type}, {suggestions} \n"
150-
"This tendency will be ignored.",
143+
f"Unsupported tendency type: '{tendency_type}'.\n"
144+
f"Did you mean {suggestion}? \n"
145+
"This tendency will be ignored."
151146
)
152147
self.annotations.add(line_number, error_msg, is_warning=True)
153148
return None

0 commit comments

Comments
 (0)