generated from Hazel/python-project
feat: removed none type hints
This commit is contained in:
parent
b10cdd1201
commit
27a04b0e2e
@ -6,17 +6,6 @@ import pycountry
|
|||||||
from . import config
|
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):
|
class EmptyCountryException(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -34,17 +23,16 @@ class Country:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, country: Optional[str] = None, pycountry_object = None) -> None:
|
def __init__(self, country: Optional[str] = None, pycountry_object = None) -> None:
|
||||||
self.pycountry_object = pycountry_object
|
if pycountry_object is None:
|
||||||
|
|
||||||
if self.pycountry_object is None:
|
|
||||||
# search for the country string instead if the pycountry_object isn't given
|
# search for the country string instead if the pycountry_object isn't given
|
||||||
# this also implements the optional fallback
|
# 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:
|
if pycountry_object is None:
|
||||||
raise EmptyCountryException(f"the country {country} was not found and config.fallback_country isn't set")
|
raise EmptyCountryException(f"the country {country} was not found and config.fallback_country isn't set")
|
||||||
|
|
||||||
|
self.pycountry_object = pycountry_object
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _search_pycountry_object(cls, country: Optional[str], is_fallback: bool = False):
|
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))
|
return cls(pycountry_object=pycountry.countries.search_fuzzy(fuzzy))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return self.pycountry_object.name
|
return self.pycountry_object.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
def alpha_2(self) -> str:
|
||||||
def alpha_2(self) -> Optional[str]:
|
|
||||||
return self.pycountry_object.alpha_2
|
return self.pycountry_object.alpha_2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
def alpha_3(self) -> str:
|
||||||
def alpha_3(self) -> Optional[str]:
|
|
||||||
return self.pycountry_object.alpha_3
|
return self.pycountry_object.alpha_3
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
def numeric(self) -> str:
|
||||||
def numeric(self) -> Optional[str]:
|
|
||||||
return self.pycountry_object.numeric
|
return self.pycountry_object.numeric
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@none_if_empty
|
def official_name(self) -> str:
|
||||||
def official_name(self) -> Optional[str]:
|
|
||||||
return self.pycountry_object.official_name
|
return self.pycountry_object.official_name
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user