Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2017-09-10 23:40:53 +0200
committerArthur de Jong <arthur@arthurdejong.org>2017-09-11 21:14:20 +0200
commit0ce5d0b21bd36cef209d7574e2ef5215df3ceca6 (patch)
treedc8ed359117720163983330b78cb1568407f50c8
parente468c1beae5cdacbb05540e39a5924bbc7acc09f (diff)
Minor code improvements (mostly PEP8)
-rw-r--r--stdnum/bg/egn.py2
-rw-r--r--stdnum/cz/dic.py2
-rw-r--r--stdnum/dk/cpr.py2
-rw-r--r--stdnum/es/cups.py2
-rw-r--r--stdnum/es/referenciacatastral.py3
-rw-r--r--stdnum/eu/nace.py2
-rw-r--r--stdnum/fr/nir.py19
-rw-r--r--stdnum/fr/siren.py3
-rw-r--r--stdnum/iban.py2
-rw-r--r--stdnum/it/codicefiscale.py2
-rw-r--r--stdnum/lv/pvn.py2
-rw-r--r--stdnum/numdb.py2
-rw-r--r--stdnum/ro/cnp.py2
-rw-r--r--stdnum/util.py2
14 files changed, 27 insertions, 20 deletions
diff --git a/stdnum/bg/egn.py b/stdnum/bg/egn.py
index 959e309..56837b4 100644
--- a/stdnum/bg/egn.py
+++ b/stdnum/bg/egn.py
@@ -86,7 +86,7 @@ def validate(number):
if len(number) != 10:
raise InvalidLength()
# check if birth date is valid
- birth_date = get_birth_date(number)
+ get_birth_date(number)
# TODO: check that the birth date is not in the future
# check the check digit
if calc_check_digit(number[:-1]) != number[-1]:
diff --git a/stdnum/cz/dic.py b/stdnum/cz/dic.py
index 66ece03..25304a1 100644
--- a/stdnum/cz/dic.py
+++ b/stdnum/cz/dic.py
@@ -65,7 +65,7 @@ def calc_check_digit_special(number):
"""Calculate the check digit for special cases. The number passed
should not have the first and last digits included."""
check = sum((8 - i) * int(n) for i, n in enumerate(number)) % 11
- return str((8 - (10 - check) % 11 ) % 10)
+ return str((8 - (10 - check) % 11) % 10)
def validate(number):
diff --git a/stdnum/dk/cpr.py b/stdnum/dk/cpr.py
index ead77df..54117fa 100644
--- a/stdnum/dk/cpr.py
+++ b/stdnum/dk/cpr.py
@@ -97,7 +97,7 @@ def validate(number):
if len(number) != 10:
raise InvalidLength()
# check if birth date is valid
- birth_date = get_birth_date(number)
+ get_birth_date(number)
# TODO: check that the birth date is not in the future
return number
diff --git a/stdnum/es/cups.py b/stdnum/es/cups.py
index a2011e2..896240a 100644
--- a/stdnum/es/cups.py
+++ b/stdnum/es/cups.py
@@ -74,7 +74,7 @@ def format(number):
number[14:18],
number[18:20],
number[20:],
- )).strip()
+ )).strip()
def calc_check_digits(number):
diff --git a/stdnum/es/referenciacatastral.py b/stdnum/es/referenciacatastral.py
index 8b32082..129bb16 100644
--- a/stdnum/es/referenciacatastral.py
+++ b/stdnum/es/referenciacatastral.py
@@ -74,8 +74,7 @@ def format(number):
number[:7],
number[7:14],
number[14:18],
- number[18:]
- ])
+ number[18:]])
# The check digit implementation is based on the Javascript
diff --git a/stdnum/eu/nace.py b/stdnum/eu/nace.py
index 64743b0..01ce652 100644
--- a/stdnum/eu/nace.py
+++ b/stdnum/eu/nace.py
@@ -67,7 +67,7 @@ def info(number):
number = compact(number)
from stdnum import numdb
info = dict()
- for n, i in numdb.get('eu/nace').info(number):
+ for _n, i in numdb.get('eu/nace').info(number):
if not i:
raise InvalidComponent()
info.update(i)
diff --git a/stdnum/fr/nir.py b/stdnum/fr/nir.py
index bbd6bc6..992fb61 100644
--- a/stdnum/fr/nir.py
+++ b/stdnum/fr/nir.py
@@ -49,6 +49,14 @@ InvalidChecksum: ...
'253072B07300470'
>>> validate('253072A07300443')
'253072A07300443'
+>>> validate('253072C07300443')
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> validate('6546546546546703')
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
>>> format('295109912611193')
'2 95 10 99 126 111 93'
"""
@@ -77,9 +85,9 @@ def validate(number):
"""Check if the number provided is valid. This checks the length
and check digits."""
number = compact(number)
- if not (number.isdigit() or (
- number[:5].isdigit() and number[7:].isdigit() and
- number[5:7] in ('2A', '2B'))):
+ if not number[:5].isdigit() or not number[7:].isdigit():
+ raise InvalidFormat()
+ if not number[5:7].isdigit() and number[5:7] not in ('2A', '2B'):
raise InvalidFormat()
if len(number) != 15:
raise InvalidLength()
@@ -99,5 +107,6 @@ def is_valid(number):
def format(number, separator=' '):
"""Reformat the number to the standard presentation format."""
number = compact(number)
- return separator.join((number[:1], number[1:3], number[3:5], number[5:7],
- number[7:10], number[10:13], number[13:]))
+ return separator.join((
+ number[:1], number[1:3], number[3:5], number[5:7], number[7:10],
+ number[10:13], number[13:]))
diff --git a/stdnum/fr/siren.py b/stdnum/fr/siren.py
index ce94841..ced8224 100644
--- a/stdnum/fr/siren.py
+++ b/stdnum/fr/siren.py
@@ -80,5 +80,4 @@ def to_tva(number):
return '%02d%s%s' % (
int(compact(number) + '12') % 97,
' ' if ' ' in number else '',
- number
- )
+ number)
diff --git a/stdnum/iban.py b/stdnum/iban.py
index 61d5eb8..c87caa8 100644
--- a/stdnum/iban.py
+++ b/stdnum/iban.py
@@ -59,7 +59,7 @@ _ibandb = numdb.get('iban')
_struct_re = re.compile(r'([1-9][0-9]*)!([nac])')
# cache of country codes to modules
-_country_modules = dict()
+_country_modules = {}
def compact(number):
diff --git a/stdnum/it/codicefiscale.py b/stdnum/it/codicefiscale.py
index 0e26722..b1b9b1f 100644
--- a/stdnum/it/codicefiscale.py
+++ b/stdnum/it/codicefiscale.py
@@ -139,7 +139,7 @@ def validate(number):
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
# check if birth date is valid
- birth_date = get_birth_date(number)
+ get_birth_date(number)
return number
diff --git a/stdnum/lv/pvn.py b/stdnum/lv/pvn.py
index 5ac0974..fbf81cb 100644
--- a/stdnum/lv/pvn.py
+++ b/stdnum/lv/pvn.py
@@ -100,7 +100,7 @@ def validate(number):
raise InvalidChecksum()
else:
# natural resident, check if birth date is valid
- birth_date = get_birth_date(number)
+ get_birth_date(number)
# TODO: check that the birth date is not in the future
if calc_check_digit_pers(number[:-1]) != number[-1]:
raise InvalidChecksum()
diff --git a/stdnum/numdb.py b/stdnum/numdb.py
index 40ebdb4..2b1a6e9 100644
--- a/stdnum/numdb.py
+++ b/stdnum/numdb.py
@@ -203,5 +203,5 @@ def get(name):
import codecs
reader = codecs.getreader('utf-8')
with reader(resource_stream(__name__, name + '.dat')) as fp:
- _open_databases[name] = db = read(fp)
+ _open_databases[name] = read(fp)
return _open_databases[name]
diff --git a/stdnum/ro/cnp.py b/stdnum/ro/cnp.py
index 6aab9ef..be815a2 100644
--- a/stdnum/ro/cnp.py
+++ b/stdnum/ro/cnp.py
@@ -84,7 +84,7 @@ def validate(number):
if len(number) != 13:
raise InvalidLength()
# check if birth date is valid
- birth_date = get_birth_date(number)
+ get_birth_date(number)
# TODO: check that the birth date is not in the future
# number[7:9] is the county, we ignore it for now, just check last digit
if calc_check_digit(number[:-1]) != number[-1]:
diff --git a/stdnum/util.py b/stdnum/util.py
index 3d4b04f..b04e2c0 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -137,7 +137,7 @@ def get_number_modules(base='stdnum'):
"""Yield all the module and package names under the specified module."""
__import__(base)
module = sys.modules[base]
- for loader, name, is_pkg in pkgutil.walk_packages(
+ for _loader, name, _is_pkg in pkgutil.walk_packages(
module.__path__, module.__name__ + '.'):
__import__(name)
module = sys.modules[name]