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 8 additions and 7 deletions
Showing only changes of commit b10cdd1201 - Show all commits

View File

@ -1,8 +1,9 @@
from .country import Country, StrictCountry from .country import Country, StrictCountry, EmptyCountryException
from . import config from . import config
__all__ = [ __all__ = [
"Country", "Country",
"StrictCountry", "StrictCountry",
"config", "config",
"EmptyCountryException",
] ]

View File

@ -17,6 +17,10 @@ def none_if_empty(func):
return wrapper return wrapper
class EmptyCountryException(ValueError):
pass
class Country: class Country:
""" """
This gets countries based on the ISO 3166-1 standart. This gets countries based on the ISO 3166-1 standart.
@ -39,7 +43,7 @@ class Country:
if pycountry_object is None: if pycountry_object is None:
raise ValueError(f"Country {country} couldn't be found") raise EmptyCountryException(f"the country {country} was not found and config.fallback_country isn't set")
@classmethod @classmethod
@ -85,13 +89,9 @@ class Country:
def from_fuzzy(cls, fuzzy: str) -> Country: def from_fuzzy(cls, fuzzy: str) -> Country:
return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy)) return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy))
@property
def is_empty(self) -> bool:
return self.pycountry_object is None
@property @property
@none_if_empty @none_if_empty
def name(self) -> Optional[str]: def name(self) -> str:
return self.pycountry_object.name return self.pycountry_object.name
@property @property