making levenstein lib optional

This commit is contained in:
Klemek
2020-05-01 22:59:40 +02:00
parent dca12b5d32
commit 2070307c9d
+6
View File
@@ -6,7 +6,11 @@ from urllib.error import URLError, HTTPError
from urllib.parse import urlparse
import os.path as path
from typing import List, Optional, Union, Tuple, BinaryIO
try:
from Levenshtein import distance
except ModuleNotFoundError:
distance = None
# region path utils
@@ -137,6 +141,8 @@ def split_arguments(args: Union[List[str], Tuple[str]], separator: str) -> List[
def find_nearest(word: str, wlist: List[str], threshold: int = 5) -> Optional[str]:
if distance is None:
return None
distances = [
(distance(word, w), # distance
abs(len(w) - len(word)), # length diff