27 check_missing_argument_separator=False):
28 recommendations = self.
findfind(name, candidates, max_matches)
30 return self.
formatformat(message, recommendations)
31 if check_missing_argument_separator
and name:
34 return f
'{message} {recommendation}'
38 def find(self, name, candidates, max_matches=10):
39 if not name
or not candidates:
44 norm_matches = difflib.get_close_matches(
45 norm_name, norm_candidates, n=max_matches, cutoff=cutoff
58 def format(self, message, recommendations):
60 message +=
" Did you mean:"
61 for rec
in recommendations:
62 message +=
"\n %s" % rec
67 for cand
in sorted(candidates):
69 norm_candidates.setdefault(norm, []).append(cand)
70 return norm_candidates
74 for match
in norm_matches:
75 candidates.extend(norm_candidates[match])
85 cutoff = min_cutoff + len(string) * step
86 return min(cutoff, max_cutoff)
91 matches = [c
for c
in candidates
if name.startswith(c)]
95 return (f
"Did you try using keyword {seq2str(candidates, lastsep=' or ')} "
96 f
"and forgot to use enough whitespace between keyword and arguments?")
def format(self, message, recommendations)
Add recommendations to the given message.
def _check_missing_argument_separator(self, name, candidates)
def _calculate_cutoff(self, string, min_cutoff=0.5, max_cutoff=0.85, step=0.03)
Calculate a cutoff depending on string length.
def __init__(self, normalizer=None)
def _get_original_candidates(self, norm_matches, norm_candidates)
def _get_normalized_candidates(self, candidates)
def find(self, name, candidates, max_matches=10)
Return a list of close matches to name from candidates.
def find_and_format(self, name, candidates, message, max_matches=10, check_missing_argument_separator=False)