Skip to content

Commit 1be8aab

Browse files
authored
Reintroducing support for Python 3.7 and 3.8 (#70)
Merge of commits with the following commit messages: * Attempted fix of importlib * Removed walrus operator * Fix for mypy in 3.7 and 3.8 * Another attempt to fix mypy * Another attempt to fix mypy number 2 Fixes #69
1 parent 21a25d2 commit 1be8aab

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

.github/workflows/build_and_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
os: [ubuntu-latest]
21-
python-version: [3.9, '3.10', '3.11', '3.12']
21+
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12']
2222
steps:
2323
- uses: actions/checkout@v4
2424

bankid/certutils.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
"""
77

88
import os
9+
import sys
910
import subprocess
1011
from typing import Tuple, Union
1112

1213
import pathlib
13-
import importlib.resources
14+
if sys.version_info < (3, 9):
15+
import importlib_resources as impres
16+
else:
17+
import importlib.resources as impres
1418

1519
from bankid.certs import get_test_cert_p12
1620
from bankid.exceptions import BankIDError
@@ -19,7 +23,7 @@
1923

2024

2125
def resolve_cert_path(file: str) -> pathlib.Path:
22-
path = importlib.resources.files("bankid.certs").joinpath(file)
26+
path = impres.files("bankid.certs").joinpath(file)
2327
assert isinstance(path, pathlib.Path)
2428
return path
2529

@@ -37,7 +41,8 @@ def create_bankid_test_server_cert_and_key(destination_path: str = ".") -> Tuple
3741
:rtype: tuple
3842
3943
"""
40-
if test_cert_file := os.getenv("TEST_CERT_FILE"):
44+
test_cert_file = os.getenv("TEST_CERT_FILE")
45+
if test_cert_file is not None:
4146
certificate, key = split_certificate(
4247
test_cert_file, destination_path, password=_TEST_CERT_PASSWORD
4348
)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
httpx
2+
importlib_resources; python_version < "3.9"

tests/test_exceptions.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from collections import namedtuple
2+
import sys
23
from typing import Union
34

45
import pytest
56

67
import bankid
78

9+
if sys.version_info >= (3, 9):
10+
from builtins import type as Type
11+
else:
12+
# Remove once PyBankID no longer support Python 3.8 or lower
13+
from typing import Type
14+
815

916
@pytest.mark.parametrize(
1017
"exception_class,rfa",
@@ -19,7 +26,7 @@
1926
(bankid.exceptions.BankIDError, None),
2027
],
2128
)
22-
def test_exceptions(exception_class: type[Exception], rfa: Union[int, None]) -> None:
29+
def test_exceptions(exception_class: Type[Exception], rfa: Union[int, None]) -> None:
2330
e = exception_class()
2431
assert isinstance(e, bankid.exceptions.BankIDError)
2532
assert e.rfa == rfa
@@ -38,7 +45,7 @@ def test_exceptions(exception_class: type[Exception], rfa: Union[int, None]) ->
3845
(bankid.exceptions.BankIDError, "Unknown error code"),
3946
],
4047
)
41-
def test_error_class_factory(exception_class: type[Exception], error_code: str) -> None:
48+
def test_error_class_factory(exception_class: Type[Exception], error_code: str) -> None:
4249
MockResponse = namedtuple("MockResponse", ["json"])
4350
response = MockResponse(json=lambda: {"errorCode": error_code})
4451
# error: Argument 1 to "get_json_error_class" has incompatible type "MockResponse@41"; expected "Response" [arg-type]

0 commit comments

Comments
 (0)