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():
|
||||
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
|
||||
if config.allow_fuzzy_search:
|
||||
found_countries = pycountry.countries.search_fuzzy(country)
|
||||
if len(found_countries):
|
||||
return found_countries[0]
|
||||
# fuzzy search raises lookup error if nothing was found
|
||||
try:
|
||||
found_countries = pycountry.countries.search_fuzzy(country)
|
||||
if len(found_countries):
|
||||
return found_countries[0]
|
||||
except LookupError:
|
||||
pass
|
||||
|
||||
|
||||
@classmethod
|
||||
def search(cls, country: Optional[str]) -> Optional[Country]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user