Skip to content

Commit 0cedf8b

Browse files
committed
Add typing
1 parent da9a8bd commit 0cedf8b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

stdnum/eu/excise.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@
4040
'LU00000987ABC'
4141
"""
4242

43+
from __future__ import annotations
44+
4345
from stdnum.eu.vat import MEMBER_STATES
4446
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
4653

4754

4855
_country_modules = dict()
@@ -51,7 +58,7 @@
5158
"""The WSDL URL of the System for Exchange of Excise Data (SEED)."""
5259

5360

54-
def _get_cc_module(cc):
61+
def _get_cc_module(cc: str) -> NumberValidationModule | None:
5562
"""Get the Excise number module based on the country code."""
5663
cc = cc.lower()
5764
if cc not in MEMBER_STATES:
@@ -61,14 +68,14 @@ def _get_cc_module(cc):
6168
return _country_modules[cc]
6269

6370

64-
def compact(number):
71+
def compact(number: str) -> str:
6572
"""Convert the number to the minimal representation. This strips the number
6673
of any valid separators and removes surrounding whitespace."""
6774
number = clean(number, ' ').upper().strip()
6875
return number
6976

7077

71-
def validate(number):
78+
def validate(number: str) -> str:
7279
"""Check if the number is a valid Excise number."""
7380
number = clean(number, ' ').upper().strip()
7481
cc = number[:2]
@@ -80,19 +87,22 @@ def validate(number):
8087
return number
8188

8289

83-
def is_valid(number):
90+
def is_valid(number: str) -> bool:
8491
"""Check if the number is a valid Excise number."""
8592
try:
8693
return bool(validate(number))
8794
except ValidationError:
8895
return False
8996

9097

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)
92102
"""Query the online European Commission System for Exchange of Excise Data
93103
(SEED) for validity of the provided number. Note that the service has
94104
usage limitations (see the VIES website for details). The timeout is in
95105
seconds. This returns a dict-like object."""
96106
number = compact(number)
97107
client = get_soap_client(seed_wsdl, timeout)
98-
return client.verifyExcise(number)
108+
return client.verifyExcise(number) # type: ignore[no-any-return]

stdnum/fr/accise.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,23 @@
5353
InvalidFormat: ...
5454
"""
5555

56+
from __future__ import annotations
57+
5658
from stdnum.exceptions import *
5759
from stdnum.util import clean, isdigits
5860

5961

6062
OPERATORS = set(['E', 'N', 'C', 'B'])
6163

6264

63-
def compact(number):
65+
def compact(number: str) -> str:
6466
"""Convert the number to the minimal representation. This strips the number
6567
of any valid separators and removes surrounding whitespace."""
6668
number = clean(number, ' ').upper().strip()
6769
return number
6870

6971

70-
def validate(number):
72+
def validate(number: str) -> str:
7173
"""Check if the number is a valid accise number. This checks the length,
7274
formatting."""
7375
number = clean(number, ' ').upper().strip()
@@ -87,7 +89,7 @@ def validate(number):
8789
return number
8890

8991

90-
def is_valid(number):
92+
def is_valid(number: str) -> bool:
9193
"""Check if the number is a valid accise number."""
9294
try:
9395
return bool(validate(number))

tests/test_eu_excise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestSeed(unittest.TestCase):
3636
"""Test the SEED web service provided by the European commission for
3737
validation Excise numbers of European countries."""
3838

39-
def test_check_seed(self):
39+
def test_check_seed(self) -> None:
4040
"""Test stdnum.eu.excise.check_seed()"""
4141
result = excise.check_seed('FR012907E0820')
4242
self.assertTrue('errorDescription' not in result)

0 commit comments

Comments
 (0)