From 27a04b0e2e6b7e49279cfd1af207e781ac865060 Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 12 Jun 2025 13:15:56 +0200 Subject: [PATCH] feat: removed none type hints --- pycountry_wrapper/country.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/pycountry_wrapper/country.py b/pycountry_wrapper/country.py index e0ced19..a337fd0 100644 --- a/pycountry_wrapper/country.py +++ b/pycountry_wrapper/country.py @@ -6,17 +6,6 @@ import pycountry from . import config -def none_if_empty(func): - @wraps(func) - def wrapper(self, *args, **kwargs): - if self.is_empty: - return None - - return func(self, *args, **kwargs) - - return wrapper - - class EmptyCountryException(ValueError): pass @@ -34,17 +23,16 @@ class Country: """ def __init__(self, country: Optional[str] = None, pycountry_object = None) -> None: - self.pycountry_object = pycountry_object - - if self.pycountry_object is None: + if pycountry_object is None: # search for the country string instead if the pycountry_object isn't given # this also implements the optional fallback - self.pycountry_object = self._search_pycountry_object(country=country) + pycountry_object = self._search_pycountry_object(country=country) - if pycountry_object is None: raise EmptyCountryException(f"the country {country} was not found and config.fallback_country isn't set") - + + self.pycountry_object = pycountry_object + @classmethod def _search_pycountry_object(cls, country: Optional[str], is_fallback: bool = False): @@ -90,28 +78,23 @@ class Country: return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy)) @property - @none_if_empty def name(self) -> str: return self.pycountry_object.name @property - @none_if_empty - def alpha_2(self) -> Optional[str]: + def alpha_2(self) -> str: return self.pycountry_object.alpha_2 @property - @none_if_empty - def alpha_3(self) -> Optional[str]: + def alpha_3(self) -> str: return self.pycountry_object.alpha_3 @property - @none_if_empty - def numeric(self) -> Optional[str]: + def numeric(self) -> str: return self.pycountry_object.numeric @property - @none_if_empty - def official_name(self) -> Optional[str]: + def official_name(self) -> str: return self.pycountry_object.official_name def __str__(self) -> str: