generated from Hazel/python-project
fix: lookup error for fuzzy search
This commit is contained in:
parent
65b0c2b8e6
commit
af3fff8559
@ -5,4 +5,4 @@ from . import Country, EmptyCountry
|
|||||||
def cli():
|
def cli():
|
||||||
print(f"Running {__name__} version {__version__} from __main__.py")
|
print(f"Running {__name__} version {__version__} from __main__.py")
|
||||||
|
|
||||||
print(EmptyCountry(country="doesn't exist").name)
|
print(EmptyCountry(country="zwx").name)
|
@ -58,9 +58,14 @@ class Country:
|
|||||||
|
|
||||||
# fuzzy search if enabled
|
# fuzzy search if enabled
|
||||||
if config.allow_fuzzy_search:
|
if config.allow_fuzzy_search:
|
||||||
|
# fuzzy search raises lookup error if nothing was found
|
||||||
|
try:
|
||||||
found_countries = pycountry.countries.search_fuzzy(country)
|
found_countries = pycountry.countries.search_fuzzy(country)
|
||||||
if len(found_countries):
|
if len(found_countries):
|
||||||
return found_countries[0]
|
return found_countries[0]
|
||||||
|
except LookupError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def search(cls, country: Optional[str]) -> Optional[Country]:
|
def search(cls, country: Optional[str]) -> Optional[Country]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user