40
40
'LU00000987ABC'
41
41
"""
42
42
43
+ from __future__ import annotations
44
+
43
45
from stdnum .eu .vat import MEMBER_STATES
44
46
from stdnum .exceptions import *
45
- from stdnum .util import clean , get_cc_module , get_soap_client
47
+ from stdnum .util import (
48
+ NumberValidationModule , clean , get_cc_module , get_soap_client )
49
+
50
+ TYPE_CHECKING = False
51
+ if TYPE_CHECKING : # pragma: no cover (typechecking only import)
52
+ from typing import Any
46
53
47
54
48
55
_country_modules = dict ()
51
58
"""The WSDL URL of the System for Exchange of Excise Data (SEED)."""
52
59
53
60
54
- def _get_cc_module (cc ) :
61
+ def _get_cc_module (cc : str ) -> NumberValidationModule | None :
55
62
"""Get the Excise number module based on the country code."""
56
63
cc = cc .lower ()
57
64
if cc not in MEMBER_STATES :
@@ -61,14 +68,14 @@ def _get_cc_module(cc):
61
68
return _country_modules [cc ]
62
69
63
70
64
- def compact (number ) :
71
+ def compact (number : str ) -> str :
65
72
"""Convert the number to the minimal representation. This strips the number
66
73
of any valid separators and removes surrounding whitespace."""
67
74
number = clean (number , ' ' ).upper ().strip ()
68
75
return number
69
76
70
77
71
- def validate (number ) :
78
+ def validate (number : str ) -> str :
72
79
"""Check if the number is a valid Excise number."""
73
80
number = clean (number , ' ' ).upper ().strip ()
74
81
cc = number [:2 ]
@@ -80,19 +87,22 @@ def validate(number):
80
87
return number
81
88
82
89
83
- def is_valid (number ) :
90
+ def is_valid (number : str ) -> bool :
84
91
"""Check if the number is a valid Excise number."""
85
92
try :
86
93
return bool (validate (number ))
87
94
except ValidationError :
88
95
return False
89
96
90
97
91
- def check_seed (number , timeout = 30 ): # pragma: no cover (not part of normal test suite)
98
+ def check_seed (
99
+ number : str ,
100
+ timeout : float = 30
101
+ ) -> dict [str , Any ]: # pragma: no cover (not part of normal test suite)
92
102
"""Query the online European Commission System for Exchange of Excise Data
93
103
(SEED) for validity of the provided number. Note that the service has
94
104
usage limitations (see the VIES website for details). The timeout is in
95
105
seconds. This returns a dict-like object."""
96
106
number = compact (number )
97
107
client = get_soap_client (seed_wsdl , timeout )
98
- return client .verifyExcise (number )
108
+ return client .verifyExcise (number ) # type: ignore[no-any-return]
0 commit comments