diff --git a/pycountry_wrapper/__init__.py b/pycountry_wrapper/__init__.py index 257425a..b11f108 100644 --- a/pycountry_wrapper/__init__.py +++ b/pycountry_wrapper/__init__.py @@ -1,8 +1,9 @@ -from .country import Country, StrictCountry +from .country import Country, StrictCountry, EmptyCountryException from . import config __all__ = [ "Country", "StrictCountry", "config", + "EmptyCountryException", ] diff --git a/pycountry_wrapper/country.py b/pycountry_wrapper/country.py index 845ddd7..e0ced19 100644 --- a/pycountry_wrapper/country.py +++ b/pycountry_wrapper/country.py @@ -17,6 +17,10 @@ def none_if_empty(func): return wrapper +class EmptyCountryException(ValueError): + pass + + class Country: """ This gets countries based on the ISO 3166-1 standart. @@ -39,7 +43,7 @@ class Country: 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 @@ -85,13 +89,9 @@ class Country: def from_fuzzy(cls, fuzzy: str) -> Country: return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy)) - @property - def is_empty(self) -> bool: - return self.pycountry_object is None - @property @none_if_empty - def name(self) -> Optional[str]: + def name(self) -> str: return self.pycountry_object.name @property