Skip to content

Commit 654b613

Browse files
author
smkc
committed
Clean up lint and type issues
1 parent e896d42 commit 654b613

59 files changed

Lines changed: 1844 additions & 1065 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/send_invoice_json.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ def main() -> None:
6666
symmetric_cert = next(
6767
c for c in certs if "SymmetricKeyEncryption" in (c.get("usage") or [])
6868
)["certificate"]
69-
access_token = AuthCoordinator(client.auth).authenticate_with_ksef_token(
70-
token=token,
71-
public_certificate=token_cert,
72-
context_identifier_type=context_type,
73-
context_identifier_value=context_value,
74-
max_attempts=90,
75-
poll_interval_seconds=2.0,
76-
).tokens.access_token.token
69+
access_token = (
70+
AuthCoordinator(client.auth)
71+
.authenticate_with_ksef_token(
72+
token=token,
73+
public_certificate=token_cert,
74+
context_identifier_type=context_type,
75+
context_identifier_value=context_value,
76+
max_attempts=90,
77+
poll_interval_seconds=2.0,
78+
)
79+
.tokens.access_token.token
80+
)
7781
session = OnlineSessionWorkflow(client.sessions).open_session(
7882
form_code={"systemCode": "FA (3)", "schemaVersion": "1-0E", "value": "FA"},
7983
public_certificate=symmetric_cert,

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ warn_unused_configs = true
6060
disallow_untyped_defs = false
6161
no_implicit_optional = true
6262
check_untyped_defs = true
63+
64+
[[tool.mypy.overrides]]
65+
module = ["qrcode", "qrcode.*", "PIL", "PIL.*", "xmlsec", "lxml", "lxml.*"]
66+
ignore_missing_imports = true

src/ksef_client/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""KSeF Python SDK."""
22

3+
from .client import AsyncKsefClient, KsefClient
34
from .config import KsefClientOptions, KsefEnvironment
4-
from .client import KsefClient, AsyncKsefClient
5-
from .exceptions import KsefApiError, KsefRateLimitError, KsefHttpError
5+
from .exceptions import KsefApiError, KsefHttpError, KsefRateLimitError
66
from .models import (
77
AuthenticationChallengeResponse,
88
AuthenticationInitResponse,
9-
AuthenticationTokensResponse,
109
AuthenticationTokenRefreshResponse,
11-
TokenInfo,
12-
StatusInfo,
10+
AuthenticationTokensResponse,
11+
InvoiceExportStatusResponse,
1312
InvoicePackage,
1413
InvoicePackagePart,
15-
InvoiceExportStatusResponse,
14+
StatusInfo,
15+
TokenInfo,
1616
)
1717

1818
__all__ = [

src/ksef_client/client.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
from __future__ import annotations
22

3-
from typing import Optional
4-
3+
from .clients.auth import AsyncAuthClient, AuthClient
4+
from .clients.certificates import AsyncCertificatesClient, CertificatesClient
5+
from .clients.invoices import AsyncInvoicesClient, InvoicesClient
6+
from .clients.limits import AsyncLimitsClient, LimitsClient
7+
from .clients.peppol import AsyncPeppolClient, PeppolClient
8+
from .clients.permissions import AsyncPermissionsClient, PermissionsClient
9+
from .clients.rate_limits import AsyncRateLimitsClient, RateLimitsClient
10+
from .clients.security import AsyncSecurityClient, SecurityClient
11+
from .clients.sessions import AsyncSessionsClient, SessionsClient
12+
from .clients.testdata import AsyncTestDataClient, TestDataClient
13+
from .clients.tokens import AsyncTokensClient, TokensClient
514
from .config import KsefClientOptions
6-
from .http import BaseHttpClient, AsyncBaseHttpClient
7-
from .clients.auth import AuthClient, AsyncAuthClient
8-
from .clients.sessions import SessionsClient, AsyncSessionsClient
9-
from .clients.invoices import InvoicesClient, AsyncInvoicesClient
10-
from .clients.permissions import PermissionsClient, AsyncPermissionsClient
11-
from .clients.certificates import CertificatesClient, AsyncCertificatesClient
12-
from .clients.tokens import TokensClient, AsyncTokensClient
13-
from .clients.limits import LimitsClient, AsyncLimitsClient
14-
from .clients.rate_limits import RateLimitsClient, AsyncRateLimitsClient
15-
from .clients.security import SecurityClient, AsyncSecurityClient
16-
from .clients.testdata import TestDataClient, AsyncTestDataClient
17-
from .clients.peppol import PeppolClient, AsyncPeppolClient
15+
from .http import AsyncBaseHttpClient, BaseHttpClient
1816

1917

2018
class KsefClient:
21-
def __init__(self, options: KsefClientOptions, access_token: Optional[str] = None) -> None:
19+
def __init__(self, options: KsefClientOptions, access_token: str | None = None) -> None:
2220
self._http = BaseHttpClient(options, access_token=access_token)
2321
self.auth = AuthClient(self._http)
2422
self.sessions = SessionsClient(self._http)
@@ -39,15 +37,15 @@ def close(self) -> None:
3937
def http_client(self) -> BaseHttpClient:
4038
return self._http
4139

42-
def __enter__(self) -> "KsefClient":
40+
def __enter__(self) -> KsefClient:
4341
return self
4442

4543
def __exit__(self, exc_type, exc, tb) -> None:
4644
self.close()
4745

4846

4947
class AsyncKsefClient:
50-
def __init__(self, options: KsefClientOptions, access_token: Optional[str] = None) -> None:
48+
def __init__(self, options: KsefClientOptions, access_token: str | None = None) -> None:
5149
self._http = AsyncBaseHttpClient(options, access_token=access_token)
5250
self.auth = AsyncAuthClient(self._http)
5351
self.sessions = AsyncSessionsClient(self._http)
@@ -68,7 +66,7 @@ async def aclose(self) -> None:
6866
def http_client(self) -> AsyncBaseHttpClient:
6967
return self._http
7068

71-
async def __aenter__(self) -> "AsyncKsefClient":
69+
async def __aenter__(self) -> AsyncKsefClient:
7270
return self
7371

7472
async def __aexit__(self, exc_type, exc, tb) -> None:

src/ksef_client/clients/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from .auth import AuthClient, AsyncAuthClient
2-
from .sessions import SessionsClient, AsyncSessionsClient
3-
from .invoices import InvoicesClient, AsyncInvoicesClient
4-
from .permissions import PermissionsClient, AsyncPermissionsClient
5-
from .certificates import CertificatesClient, AsyncCertificatesClient
6-
from .tokens import TokensClient, AsyncTokensClient
7-
from .limits import LimitsClient, AsyncLimitsClient
8-
from .rate_limits import RateLimitsClient, AsyncRateLimitsClient
9-
from .security import SecurityClient, AsyncSecurityClient
10-
from .testdata import TestDataClient, AsyncTestDataClient
11-
from .peppol import PeppolClient, AsyncPeppolClient
1+
from .auth import AsyncAuthClient, AuthClient
2+
from .certificates import AsyncCertificatesClient, CertificatesClient
3+
from .invoices import AsyncInvoicesClient, InvoicesClient
4+
from .limits import AsyncLimitsClient, LimitsClient
5+
from .peppol import AsyncPeppolClient, PeppolClient
6+
from .permissions import AsyncPermissionsClient, PermissionsClient
7+
from .rate_limits import AsyncRateLimitsClient, RateLimitsClient
8+
from .security import AsyncSecurityClient, SecurityClient
9+
from .sessions import AsyncSessionsClient, SessionsClient
10+
from .testdata import AsyncTestDataClient, TestDataClient
11+
from .tokens import AsyncTokensClient, TokensClient
1212

1313
__all__ = [
1414
"AuthClient",

src/ksef_client/clients/auth.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import annotations
22

3-
from typing import Any, Optional
3+
from typing import Any
44

5-
from .base import BaseApiClient, AsyncBaseApiClient
5+
from .base import AsyncBaseApiClient, BaseApiClient
66

77

88
class AuthClient(BaseApiClient):
99
def get_active_sessions(
1010
self,
1111
*,
12-
page_size: Optional[int] = None,
13-
continuation_token: Optional[str] = None,
14-
access_token: Optional[str] = None,
12+
page_size: int | None = None,
13+
continuation_token: str | None = None,
14+
access_token: str | None = None,
1515
) -> Any:
1616
headers = {}
1717
if continuation_token:
@@ -50,7 +50,7 @@ def submit_xades_auth_request(
5050
self,
5151
signed_xml: str,
5252
*,
53-
verify_certificate_chain: Optional[bool] = None,
53+
verify_certificate_chain: bool | None = None,
5454
) -> Any:
5555
params = {}
5656
if verify_certificate_chain is not None:
@@ -72,6 +72,7 @@ def submit_xades_auth_request(
7272
return None
7373
# Response is JSON.
7474
import json as _json
75+
7576
return _json.loads(response_bytes.decode("utf-8"))
7677

7778
def submit_ksef_token_auth(self, request_payload: dict[str, Any]) -> Any:
@@ -109,9 +110,9 @@ class AsyncAuthClient(AsyncBaseApiClient):
109110
async def get_active_sessions(
110111
self,
111112
*,
112-
page_size: Optional[int] = None,
113-
continuation_token: Optional[str] = None,
114-
access_token: Optional[str] = None,
113+
page_size: int | None = None,
114+
continuation_token: str | None = None,
115+
access_token: str | None = None,
115116
) -> Any:
116117
headers = {}
117118
if continuation_token:
@@ -150,7 +151,7 @@ async def submit_xades_auth_request(
150151
self,
151152
signed_xml: str,
152153
*,
153-
verify_certificate_chain: Optional[bool] = None,
154+
verify_certificate_chain: bool | None = None,
154155
) -> Any:
155156
params = {}
156157
if verify_certificate_chain is not None:
@@ -171,6 +172,7 @@ async def submit_xades_auth_request(
171172
if not response_bytes:
172173
return None
173174
import json as _json
175+
174176
return _json.loads(response_bytes.decode("utf-8"))
175177

176178
async def submit_ksef_token_auth(self, request_payload: dict[str, Any]) -> Any:

src/ksef_client/clients/base.py

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
from __future__ import annotations
22

3-
from typing import Any, Optional
3+
from typing import Any, Protocol
44

5-
from ..http import BaseHttpClient, AsyncBaseHttpClient
5+
from ..http import HttpResponse
6+
7+
8+
class _RequestClient(Protocol):
9+
def request(self, *args: Any, **kwargs: Any) -> HttpResponse: ...
10+
11+
12+
class _AsyncRequestClient(Protocol):
13+
async def request(self, *args: Any, **kwargs: Any) -> HttpResponse: ...
614

715

816
class BaseApiClient:
9-
def __init__(self, http_client: BaseHttpClient) -> None:
17+
def __init__(self, http_client: _RequestClient) -> None:
1018
self._http = http_client
1119

1220
def _request_json(
1321
self,
1422
method: str,
1523
path: str,
1624
*,
17-
params: Optional[dict[str, Any]] = None,
18-
headers: Optional[dict[str, str]] = None,
19-
json: Optional[dict[str, Any]] = None,
20-
access_token: Optional[str] = None,
21-
refresh_token: Optional[str] = None,
25+
params: dict[str, Any] | None = None,
26+
headers: dict[str, str] | None = None,
27+
json: dict[str, Any] | None = None,
28+
access_token: str | None = None,
29+
refresh_token: str | None = None,
2230
skip_auth: bool = False,
23-
expected_status: Optional[set[int]] = None,
31+
expected_status: set[int] | None = None,
2432
) -> Any:
2533
response = self._http.request(
2634
method,
@@ -42,13 +50,13 @@ def _request_bytes(
4250
method: str,
4351
path: str,
4452
*,
45-
params: Optional[dict[str, Any]] = None,
46-
headers: Optional[dict[str, str]] = None,
47-
json: Optional[dict[str, Any]] = None,
48-
data: Optional[bytes] = None,
49-
access_token: Optional[str] = None,
53+
params: dict[str, Any] | None = None,
54+
headers: dict[str, str] | None = None,
55+
json: dict[str, Any] | None = None,
56+
data: bytes | None = None,
57+
access_token: str | None = None,
5058
skip_auth: bool = False,
51-
expected_status: Optional[set[int]] = None,
59+
expected_status: set[int] | None = None,
5260
) -> bytes:
5361
response = self._http.request(
5462
method,
@@ -68,13 +76,13 @@ def _request_raw(
6876
method: str,
6977
path: str,
7078
*,
71-
params: Optional[dict[str, Any]] = None,
72-
headers: Optional[dict[str, str]] = None,
73-
json: Optional[dict[str, Any]] = None,
74-
data: Optional[bytes] = None,
75-
access_token: Optional[str] = None,
79+
params: dict[str, Any] | None = None,
80+
headers: dict[str, str] | None = None,
81+
json: dict[str, Any] | None = None,
82+
data: bytes | None = None,
83+
access_token: str | None = None,
7684
skip_auth: bool = False,
77-
expected_status: Optional[set[int]] = None,
85+
expected_status: set[int] | None = None,
7886
):
7987
return self._http.request(
8088
method,
@@ -90,21 +98,21 @@ def _request_raw(
9098

9199

92100
class AsyncBaseApiClient:
93-
def __init__(self, http_client: AsyncBaseHttpClient) -> None:
101+
def __init__(self, http_client: _AsyncRequestClient) -> None:
94102
self._http = http_client
95103

96104
async def _request_json(
97105
self,
98106
method: str,
99107
path: str,
100108
*,
101-
params: Optional[dict[str, Any]] = None,
102-
headers: Optional[dict[str, str]] = None,
103-
json: Optional[dict[str, Any]] = None,
104-
access_token: Optional[str] = None,
105-
refresh_token: Optional[str] = None,
109+
params: dict[str, Any] | None = None,
110+
headers: dict[str, str] | None = None,
111+
json: dict[str, Any] | None = None,
112+
access_token: str | None = None,
113+
refresh_token: str | None = None,
106114
skip_auth: bool = False,
107-
expected_status: Optional[set[int]] = None,
115+
expected_status: set[int] | None = None,
108116
) -> Any:
109117
response = await self._http.request(
110118
method,
@@ -126,13 +134,13 @@ async def _request_bytes(
126134
method: str,
127135
path: str,
128136
*,
129-
params: Optional[dict[str, Any]] = None,
130-
headers: Optional[dict[str, str]] = None,
131-
json: Optional[dict[str, Any]] = None,
132-
data: Optional[bytes] = None,
133-
access_token: Optional[str] = None,
137+
params: dict[str, Any] | None = None,
138+
headers: dict[str, str] | None = None,
139+
json: dict[str, Any] | None = None,
140+
data: bytes | None = None,
141+
access_token: str | None = None,
134142
skip_auth: bool = False,
135-
expected_status: Optional[set[int]] = None,
143+
expected_status: set[int] | None = None,
136144
) -> bytes:
137145
response = await self._http.request(
138146
method,
@@ -152,13 +160,13 @@ async def _request_raw(
152160
method: str,
153161
path: str,
154162
*,
155-
params: Optional[dict[str, Any]] = None,
156-
headers: Optional[dict[str, str]] = None,
157-
json: Optional[dict[str, Any]] = None,
158-
data: Optional[bytes] = None,
159-
access_token: Optional[str] = None,
163+
params: dict[str, Any] | None = None,
164+
headers: dict[str, str] | None = None,
165+
json: dict[str, Any] | None = None,
166+
data: bytes | None = None,
167+
access_token: str | None = None,
160168
skip_auth: bool = False,
161-
expected_status: Optional[set[int]] = None,
169+
expected_status: set[int] | None = None,
162170
):
163171
return await self._http.request(
164172
method,

0 commit comments

Comments
 (0)