Skip to content

Commit 43cfd29

Browse files
committed
Merge branch 'master' into mypy
2 parents 152d4c5 + bc689fd commit 43cfd29

File tree

12 files changed

+82
-37
lines changed

12 files changed

+82
-37
lines changed

.github/workflows/test.yml

-16
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ on:
99
- cron: '9 0 * * 1'
1010

1111
jobs:
12-
test_legacy:
13-
runs-on: ubuntu-20.04
14-
strategy:
15-
fail-fast: false
16-
matrix:
17-
python-version: [3.7]
18-
steps:
19-
- uses: actions/checkout@v3
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v4
22-
with:
23-
python-version: ${{ matrix.python-version }}
24-
- name: Install dependencies
25-
run: python -m pip install --upgrade pip tox
26-
- name: Run tox
27-
run: tox -e "$(echo py${{ matrix.python-version }} | sed -e 's/[.]//g;s/pypypy/pypy/')" --skip-missing-interpreters false
2812
test:
2913
runs-on: ubuntu-latest
3014
strategy:

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
'Operating System :: OS Independent',
6464
'Programming Language :: Python',
6565
'Programming Language :: Python :: 3',
66-
'Programming Language :: Python :: 3.7',
6766
'Programming Language :: Python :: 3.8',
6867
'Programming Language :: Python :: 3.9',
6968
'Programming Language :: Python :: 3.10',

stdnum/be/nn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def get_birth_month(number: str) -> int | None:
184184
def get_birth_date(number: str) -> datetime.date | None:
185185
"""Return the date of birth."""
186186
year, month, day = _get_birth_date_parts(compact(number))
187-
if year is not None and month is not None and day is not None:
187+
if year and month and day:
188188
return datetime.date(year, month, day)
189189
return None
190190

stdnum/cz/rc.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# rc.py - functions for handling Czech birth numbers
22
# coding: utf-8
33
#
4-
# Copyright (C) 2012-2019 Arthur de Jong
4+
# Copyright (C) 2012-2025 Arthur de Jong
55
#
66
# This library is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU Lesser General Public
@@ -91,14 +91,10 @@ def validate(number: str) -> str:
9191
if len(number) not in (9, 10):
9292
raise InvalidLength()
9393
# check if birth date is valid
94-
birth_date = get_birth_date(number)
95-
# TODO: check that the birth date is not in the future
94+
get_birth_date(number)
9695
# check the check digit (10 digit numbers only)
9796
if len(number) == 10:
98-
check = int(number[:-1]) % 11
99-
# before 1985 the checksum could be 0 or 10
100-
if birth_date < datetime.date(1985, 1, 1):
101-
check = check % 10
97+
check = int(number[:-1]) % 11 % 10
10298
if number[-1] != str(check):
10399
raise InvalidChecksum()
104100
return number

stdnum/do/cedula.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ def format(number: str) -> str:
179179
return '-'.join((number[:3], number[3:-1], number[-1]))
180180

181181

182-
def check_dgii(number: str, timeout: float = 30) -> dict[str, t.Any] | None: # pragma: no cover
182+
def check_dgii(
183+
number: str,
184+
timeout: float = 30,
185+
verify: bool = True
186+
) -> dict[str, t.Any] | None: # pragma: no cover
183187
"""Lookup the number using the DGII online web service.
184188
185189
This uses the validation service run by the the Dirección General de
@@ -201,7 +205,7 @@ def check_dgii(number: str, timeout: float = 30) -> dict[str, t.Any] | None: #
201205
# this function isn't automatically tested because it would require
202206
# network access for the tests and unnecessarily load the online service
203207
# we use the RNC implementation and change the rnc result to cedula
204-
result = rnc.check_dgii(number, timeout)
208+
result = rnc.check_dgii(number, timeout, verify)
205209
if result and 'rnc' in result:
206210
result['cedula'] = result.pop('rnc')
207211
return result

stdnum/gs1_128.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def encode(data: t.Mapping[str, object], separator: str = '', parentheses: bool
249249
mod.validate(value)
250250
value = _encode_value(info['format'], info['type'], value)
251251
# store variable-sized values separate from fixed-size values
252-
if info.get('fnc1', False):
252+
if info.get('fnc1'):
253253
variable_values.append((ai_fmt % ai, info['format'], info['type'], value))
254254
else:
255255
fixed_values.append(ai_fmt % ai + value)

stdnum/vatin.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ def _get_cc_module(cc: str) -> t.NumberValidationModule:
6767
raise InvalidFormat()
6868
if cc not in _country_modules:
6969
_country_modules[cc] = get_cc_module(cc, 'vat')
70-
7170
module = _country_modules[cc]
72-
if module is None:
71+
if not module:
7372
raise InvalidComponent() # unknown/unsupported country code
7473
return module
7574

tests/test_be_iban.doctest

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Traceback (most recent call last):
3737
InvalidChecksum: ...
3838

3939

40+
Some bank account numbers don't have a BIC.
41+
(this is a constructed bank account number, no actual one was found in the wild)
42+
43+
>>> iban.validate('BE45102000000089')
44+
'BE45102000000089'
45+
>>> iban.to_bic('BE45102000000089') is None
46+
True
47+
48+
4049
These should all be valid numbers combined with the appropriate BIC code for
4150
the IBAN.
4251

tests/test_cz_rc.doctest

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
test_cz_rc.doctest - more detailed doctests for stdnum.cz.rc
2+
3+
Copyright (C) 2025 Arthur de Jong
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
02110-1301 USA
19+
20+
21+
This file contains more detailed doctests for the stdnum.cz.rc
22+
module.
23+
24+
>>> from stdnum.cz import rc
25+
26+
27+
28+
These have been found online and should all be valid numbers.
29+
30+
>>> numbers = '''
31+
...
32+
... 8801251680
33+
...
34+
... '''
35+
>>> [x for x in numbers.splitlines() if x and not rc.is_valid(x)]
36+
[]

tests/test_do_cedula.py

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class TestDGII(unittest.TestCase):
3636
"""Test the web services provided by the the Dirección General de
3737
Impuestos Internos (DGII), the Dominican Republic tax department."""
3838

39+
# Theses tests currently fail because the SOAP service at
40+
# https://www.dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx?WSDL
41+
# is no longer available. There is a new one at
42+
# https://www.dgii.gov.do/ventanillaunica/ventanillaunica.asmx?WSDL
43+
# but it has a different API and seems to require authentication.
44+
# See https://github.com/arthurdejong/python-stdnum/pull/462
45+
# and https://github.com/arthurdejong/python-stdnum/issues/461
46+
@unittest.expectedFailure
3947
def test_check_dgii(self):
4048
"""Test stdnum.do.cedula.check_dgii()"""
4149
# Test a normal valid number

tests/test_do_rnc.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class TestDGII(unittest.TestCase):
3636
"""Test the web services provided by the the Dirección General de
3737
Impuestos Internos (DGII), the Dominican Republic tax department."""
3838

39-
def setUp(self):
40-
"""Prepare the test."""
41-
# For Python 2.7 compatibility
42-
if not hasattr(self, 'assertRegex'):
43-
self.assertRegex = self.assertRegexpMatches
44-
39+
# Theses tests currently fail because the SOAP service at
40+
# https://www.dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx?WSDL
41+
# is no longer available. There is a new one at
42+
# https://www.dgii.gov.do/ventanillaunica/ventanillaunica.asmx?WSDL
43+
# but it has a different API and seems to require authentication.
44+
# See https://github.com/arthurdejong/python-stdnum/pull/462
45+
# and https://github.com/arthurdejong/python-stdnum/issues/461
46+
@unittest.expectedFailure
4547
def test_check_dgii(self):
4648
"""Test stdnum.do.rnc.check_dgii()"""
4749
# Test a normal valid number
@@ -64,6 +66,14 @@ def test_check_dgii(self):
6466
result = rnc.check_dgii('132070801')
6567
self.assertEqual(result['rnc'], '132070801')
6668

69+
# Theses tests currently fail because the SOAP service at
70+
# https://www.dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx?WSDL
71+
# is no longer available. There is a new one at
72+
# https://www.dgii.gov.do/ventanillaunica/ventanillaunica.asmx?WSDL
73+
# but it has a different API and seems to require authentication.
74+
# See https://github.com/arthurdejong/python-stdnum/pull/462
75+
# and https://github.com/arthurdejong/python-stdnum/issues/461
76+
@unittest.expectedFailure
6777
def test_search_dgii(self):
6878
"""Test stdnum.do.rnc.search_dgii()"""
6979
# Search for some existing companies

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py{37,38,39,310,311,312,313,py3},flake8,docs,headers
2+
envlist = py{38,39,310,311,312,313,py3},flake8,mypy,docs,headers
33
skip_missing_interpreters = true
44

55
[testenv]

0 commit comments

Comments
 (0)