generated from Hazel/python-project
feat: implemented empty country
This commit is contained in:
parent
af3fff8559
commit
5b724077e6
@ -1,8 +1,18 @@
|
||||
from .__about__ import __name__, __version__
|
||||
from . import Country, EmptyCountry
|
||||
|
||||
import pycountry
|
||||
|
||||
|
||||
def cli():
|
||||
print(f"Running {__name__} version {__version__} from __main__.py")
|
||||
t = pycountry.countries.get(alpha_2="DE")
|
||||
|
||||
print(EmptyCountry(country="zwx").name)
|
||||
country = EmptyCountry(pycountry_object=t)
|
||||
print(type(country))
|
||||
print(country)
|
||||
|
||||
print()
|
||||
empty_country = EmptyCountry(country="zwx")
|
||||
print(type(empty_country))
|
||||
print(empty_country)
|
@ -116,14 +116,22 @@ class EmptyCountry(Country):
|
||||
You can access the same attributes but they will just return None
|
||||
"""
|
||||
def __new__(cls, country: Optional[str] = None, pycountry_object: Optional[pycountry.db.Country] = None):
|
||||
print("new", country, pycountry_object)
|
||||
return super().__new__(cls)
|
||||
try:
|
||||
return Country(country=country, pycountry_object=pycountry_object)
|
||||
except EmptyCountryException:
|
||||
return super().__new__(cls)
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def search(cls, country: Optional[str]) -> Union[Country, EmptyCountry]:
|
||||
result = super().search(country)
|
||||
name = None # type: ignore
|
||||
alpha_2 = None # type: ignore
|
||||
alpha_3 = None # type: ignore
|
||||
numeric = None # type: ignore
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "EmptyCountry()"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "EmptyCountry()"
|
||||
|
||||
if result is None:
|
||||
return EmptyCountry()
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user