Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum/fr/siret.py
diff options
context:
space:
mode:
authorDavid Salvisberg <david.salvisberg@seantis.ch>2025-03-13 14:15:54 +0100
committerArthur de Jong <arthur@arthurdejong.org>2025-05-05 11:51:03 +0200
commit0e857fb8c5ba500a80cd20553bff488bf46b7643 (patch)
treed50fc324a77f3d142b7b3fec3dcf6bb72dcc6932 /stdnum/fr/siret.py
parentbc689fdddfb9dfa5ba60ad7bd08fb2533086d3cb (diff)
Add type hints
Closes https://github.com/arthurdejong/python-stdnum/pull/467 Closes https://github.com/arthurdejong/python-stdnum/issues/433
Diffstat (limited to 'stdnum/fr/siret.py')
-rw-r--r--stdnum/fr/siret.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/stdnum/fr/siret.py b/stdnum/fr/siret.py
index 7e728f7..477d35b 100644
--- a/stdnum/fr/siret.py
+++ b/stdnum/fr/siret.py
@@ -47,19 +47,21 @@ InvalidChecksum: ...
'732 829 320 00074'
"""
+from __future__ import annotations
+
from stdnum import luhn
from stdnum.exceptions import *
from stdnum.fr import siren
from stdnum.util import clean, isdigits
-def compact(number):
+def compact(number: str) -> str:
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
return clean(number, ' .').strip()
-def validate(number):
+def validate(number: str) -> str:
"""Check if the number is a valid SIRET. This checks the length,
formatting and check digit."""
number = compact(number)
@@ -78,7 +80,7 @@ def validate(number):
return number
-def is_valid(number):
+def is_valid(number: str) -> bool:
"""Check if the number is a valid SIRET."""
try:
return bool(validate(number))
@@ -86,7 +88,7 @@ def is_valid(number):
return False
-def to_siren(number):
+def to_siren(number: str) -> str:
"""Convert the SIRET number to a SIREN number.
The SIREN number is the 9 first digits of the SIRET number.
@@ -101,7 +103,7 @@ def to_siren(number):
return ''.join(_siren)
-def to_tva(number):
+def to_tva(number: str) -> str:
"""Convert the SIRET number to a TVA number.
The TVA number is built from the SIREN number, prepended by two extra
@@ -110,7 +112,7 @@ def to_tva(number):
return siren.to_tva(to_siren(number))
-def format(number, separator=' '):
+def format(number: str, separator: str = ' ') -> str:
"""Reformat the number to the standard presentation format."""
number = compact(number)
return separator.join((number[0:3], number[3:6], number[6:9], number[9:]))