equal
deleted
inserted
replaced
10 This allows us to catch exceptions at higher levels without forcing |
10 This allows us to catch exceptions at higher levels without forcing |
11 imports. |
11 imports. |
12 """ |
12 """ |
13 |
13 |
14 from __future__ import absolute_import |
14 from __future__ import absolute_import |
|
15 |
|
16 import difflib |
15 |
17 |
16 # Do not import anything but pycompat here, please |
18 # Do not import anything but pycompat here, please |
17 from . import pycompat |
19 from . import pycompat |
18 |
20 |
19 |
21 |
266 __bytes__ = _tobytes |
268 __bytes__ = _tobytes |
267 |
269 |
268 |
270 |
269 class PatchError(Exception): |
271 class PatchError(Exception): |
270 __bytes__ = _tobytes |
272 __bytes__ = _tobytes |
|
273 |
|
274 |
|
275 def getsimilar(symbols, value): |
|
276 sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() |
|
277 # The cutoff for similarity here is pretty arbitrary. It should |
|
278 # probably be investigated and tweaked. |
|
279 return [s for s in symbols if sim(s) > 0.6] |
|
280 |
|
281 |
|
282 def similarity_hint(similar): |
|
283 from .i18n import _ |
|
284 |
|
285 if len(similar) == 1: |
|
286 return _(b"did you mean %s?") % similar[0] |
|
287 elif similar: |
|
288 ss = b", ".join(sorted(similar)) |
|
289 return _(b"did you mean one of %s?") % ss |
|
290 else: |
|
291 return None |
271 |
292 |
272 |
293 |
273 class UnknownIdentifier(ParseError): |
294 class UnknownIdentifier(ParseError): |
274 """Exception raised when a {rev,file}set references an unknown identifier""" |
295 """Exception raised when a {rev,file}set references an unknown identifier""" |
275 |
296 |