From 0e857fb8c5ba500a80cd20553bff488bf46b7643 Mon Sep 17 00:00:00 2001 From: David Salvisberg Date: Thu, 13 Mar 2025 14:15:54 +0100 Subject: Add type hints Closes https://github.com/arthurdejong/python-stdnum/pull/467 Closes https://github.com/arthurdejong/python-stdnum/issues/433 --- stdnum/gr/amka.py | 12 +++++++----- stdnum/gr/vat.py | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'stdnum/gr') diff --git a/stdnum/gr/amka.py b/stdnum/gr/amka.py index e04efeb..bfb1ae3 100644 --- a/stdnum/gr/amka.py +++ b/stdnum/gr/amka.py @@ -41,6 +41,8 @@ datetime.date(1930, 1, 1) 'M' """ +from __future__ import annotations + import datetime from stdnum import luhn @@ -48,13 +50,13 @@ from stdnum.exceptions import * 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 get_birth_date(number): +def get_birth_date(number: str) -> datetime.date: """Split the date parts from the number and return the date of birth. Since only two digits are used for the year, the century may be incorrect.""" @@ -71,7 +73,7 @@ def get_birth_date(number): raise InvalidComponent() -def get_gender(number): +def get_gender(number: str) -> str: """Get the gender (M/F) from the person's AMKA.""" number = compact(number) if int(number[9]) % 2: @@ -80,7 +82,7 @@ def get_gender(number): return 'F' -def validate(number): +def validate(number: str) -> str: """Check if the number is a valid AMKA. This checks the length, formatting and check digit.""" number = compact(number) @@ -93,7 +95,7 @@ def validate(number): return number -def is_valid(number): +def is_valid(number: str) -> bool: """Check if the number is a valid AMKA.""" try: return bool(validate(number)) diff --git a/stdnum/gr/vat.py b/stdnum/gr/vat.py index dc13c0c..b83117e 100644 --- a/stdnum/gr/vat.py +++ b/stdnum/gr/vat.py @@ -32,11 +32,13 @@ Traceback (most recent call last): InvalidChecksum: ... """ +from __future__ import annotations + from stdnum.exceptions import * 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.""" number = clean(number, ' -./:').upper().strip() @@ -47,7 +49,7 @@ def compact(number): return number -def calc_check_digit(number): +def calc_check_digit(number: str) -> str: """Calculate the check digit. The number passed should not have the check digit included.""" checksum = 0 @@ -56,7 +58,7 @@ def calc_check_digit(number): return str(checksum * 2 % 11 % 10) -def validate(number): +def validate(number: str) -> str: """Check if the number is a valid VAT number. This checks the length, formatting and check digit.""" number = compact(number) @@ -69,7 +71,7 @@ def validate(number): return number -def is_valid(number): +def is_valid(number: str) -> bool: """Check if the number is a valid VAT number.""" try: return bool(validate(number)) -- cgit v1.2.3