Compare commits

...

2 Commits

Author SHA1 Message Date
4964d5a494 bump version 2024-11-20 12:34:16 +01:00
ba370e4638 started to use a simple value error 2024-11-20 12:34:04 +01:00
3 changed files with 6 additions and 9 deletions

View File

@ -13,7 +13,7 @@ pip install pycountry-wrapper
## Usage
```python
from pycountry_wrapper import Country, CountryDoesNotExist
from pycountry_wrapper import Country
germany = Country.from_alpha_2("DE")
print(germany)
@ -21,8 +21,8 @@ print(germany.name)
try:
does_not_exist = Country.from_alpha_2("EN")
except CountryDoesNotExist:
# if the country wasn't found, this exception is thrown
except ValueError:
# if the country wasn't found, a ValueError is raised
pass
```

View File

@ -1,2 +1,2 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
__name__ = "pycountry_wrapper"

View File

@ -1,9 +1,6 @@
from __future__ import annotations
import pycountry
class CountryDoesNotExist(Exception): pass
class Country:
"""
This gets countries based on the ISO 3166-1 standart.
@ -12,7 +9,7 @@ class Country:
- Country.from_alpha_2("DE")
- Country.from_alpha_3("DEU")
If the country couldn't be found, it raises the pycountry_wrapper.CountryDoesNotExist exception.
If the country couldn't be found, it raises a ValueError.
"""
def __new__(cls, country: str = None, pycountry_object = None, silent: bool = False):
@ -28,7 +25,7 @@ class Country:
if pycountry_object is None:
if silent:
return None
raise CountryDoesNotExist()
raise ValueError(f"Country {country} couldn't be found")
self.pycountry_object = pycountry_object
return self