making levenstein lib optional

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