Skip to content

Commit b68685c

Browse files
committed
Add typing
1 parent da9a8bd commit b68685c

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

stdnum/eu/excise.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
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+
51+
TYPE_CHECKING = False
52+
if TYPE_CHECKING: # pragma: no cover (typechecking only import)
53+
from typing import Any
4654

4755

4856
_country_modules = dict()
@@ -51,7 +59,7 @@
5159
"""The WSDL URL of the System for Exchange of Excise Data (SEED)."""
5260

5361

54-
def _get_cc_module(cc):
62+
def _get_cc_module(cc: str) -> NumberValidationModule | None:
5563
"""Get the Excise number module based on the country code."""
5664
cc = cc.lower()
5765
if cc not in MEMBER_STATES:
@@ -61,14 +69,14 @@ def _get_cc_module(cc):
6169
return _country_modules[cc]
6270

6371

64-
def compact(number):
72+
def compact(number: str) -> str:
6573
"""Convert the number to the minimal representation. This strips the number
6674
of any valid separators and removes surrounding whitespace."""
6775
number = clean(number, ' ').upper().strip()
6876
return number
6977

7078

71-
def validate(number):
79+
def validate(number: str) -> str:
7280
"""Check if the number is a valid Excise number."""
7381
number = clean(number, ' ').upper().strip()
7482
cc = number[:2]
@@ -80,19 +88,22 @@ def validate(number):
8088
return number
8189

8290

83-
def is_valid(number):
91+
def is_valid(number: str) -> bool:
8492
"""Check if the number is a valid Excise number."""
8593
try:
8694
return bool(validate(number))
8795
except ValidationError:
8896
return False
8997

9098

91-
def check_seed(number, timeout=30): # pragma: no cover (not part of normal test suite)
99+
def check_seed(
100+
number: str,
101+
timeout: float = 30
102+
) -> dict[str, Any]: # pragma: no cover (not part of normal test suite)
92103
"""Query the online European Commission System for Exchange of Excise Data
93104
(SEED) for validity of the provided number. Note that the service has
94105
usage limitations (see the VIES website for details). The timeout is in
95106
seconds. This returns a dict-like object."""
96107
number = compact(number)
97108
client = get_soap_client(seed_wsdl, timeout)
98-
return client.verifyExcise(number)
109+
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)