config_default_behaviour #1

Merged
Hazel merged 16 commits from config_default_behaviour into main 2025-06-12 14:28:04 +00:00
2 changed files with 9 additions and 4 deletions
Showing only changes of commit af3fff8559 - Show all commits

View File

@ -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)

View File

@ -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]: