Skip to content

Commit 63bcda8

Browse files
committed
vatin: Use more generic exception instead of ValidationError children
1 parent 470ecba commit 63bcda8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

stdnum/vatin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def _get_cc_module(cc):
6666
# Greece uses a "wrong" country code, special case for Northern Ireland
6767
cc = cc.lower().replace('el', 'gr').replace('xi', 'gb')
6868
if not _country_code_re.match(cc):
69-
raise InvalidFormat()
69+
raise ImportError()
7070
if cc not in _country_modules:
7171
_country_modules[cc] = get_cc_module(cc, 'vat')
7272
if not _country_modules[cc]:
73-
raise InvalidComponent() # unknown/unsupported country code
73+
raise ImportError()
7474
return _country_modules[cc]
7575

7676

@@ -98,5 +98,7 @@ def is_valid(number):
9898
"""Check if the number is a valid VAT number."""
9999
try:
100100
return bool(validate(number))
101+
except ImportError:
102+
return False
101103
except ValidationError:
102104
return False

tests/test_vatin.doctest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ Try validating not specifying a country:
6161
>>> vatin.validate('')
6262
Traceback (most recent call last):
6363
...
64-
InvalidFormat: ...
64+
ImportError: ...
6565
>>> vatin.validate('00')
6666
Traceback (most recent call last):
6767
...
68-
InvalidFormat: ...
68+
ImportError: ...
6969

7070

7171
Try to validate for countries with no VAT validation:
@@ -77,7 +77,7 @@ InvalidComponent: ...
7777
>>> vatin.validate('US')
7878
Traceback (most recent call last):
7979
...
80-
InvalidComponent: ...
80+
ImportError: ...
8181

8282

8383
Check is_valid for several scenarios:

0 commit comments

Comments
 (0)