diff --git a/.github/workflows/pytype.yml b/.github/workflows/pytype.yml index 5d84e6e..8683d1e 100644 --- a/.github/workflows/pytype.yml +++ b/.github/workflows/pytype.yml @@ -1,4 +1,4 @@ -name: "pytype" +name: 'pytype' on: pull_request: @@ -16,7 +16,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: '3.10' - name: Install Dependencies run: | diff --git a/setup.py b/setup.py index def4cfa..97fa066 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ install_requires=[ "websocket-client", ], + python_requires=">=3.10", entry_points={ "console_scripts": [ "midclt = truenas_api_client:main", diff --git a/truenas_api_client/__init__.py b/truenas_api_client/__init__.py index 520bef7..57ae351 100644 --- a/truenas_api_client/__init__.py +++ b/truenas_api_client/__init__.py @@ -41,7 +41,7 @@ import sys from threading import Event, Lock, Thread import time -from typing import Any, Literal, NotRequired, Protocol, TypeAlias, TypedDict +from typing import Any, Literal, Protocol, TypeAlias, TypedDict import urllib.parse import uuid @@ -350,6 +350,7 @@ def result(self): job['error'], trace={ 'class': job['exc_info']['type'], + 'frames': [], 'formatted': job['exception'], 'repr': job['exc_info'].get('repr', job['exception'].splitlines()[-1]), }, @@ -363,7 +364,18 @@ class _EventCallbackProtocol(Protocol): def __call__(self, mtype: str, **message: Any) -> None: ... -class _Payload(TypedDict): +class _PartialPayload(TypedDict): + """Type returned by `JSONRPCClient.event_payload`. + + Contains the required fields of `_Payload`. + + """ + callback: _EventCallbackProtocol | None + sync: bool + event: Event + + +class _Payload(_PartialPayload, total=False): """Contains data for managing a subscription. Attributes: @@ -373,15 +385,10 @@ class _Payload(TypedDict): event: `Event` that is set when the subscription should end. error: Information included in the Notification if the subscription ended in error. id: Random UUID assigned by `core.subscribe`. - ready: For backwards compatibility with `LegacyClient`. """ - callback: _EventCallbackProtocol | None - sync: bool - event: Event - error: NotRequired[str | TruenasError | None] - id: NotRequired[str] - ready: NotRequired[Event] + error: str | TruenasError | None + id: str class JSONRPCClient: diff --git a/truenas_api_client/jsonrpc.py b/truenas_api_client/jsonrpc.py index cf11f87..f0bb26c 100644 --- a/truenas_api_client/jsonrpc.py +++ b/truenas_api_client/jsonrpc.py @@ -4,7 +4,7 @@ """ import enum -from typing import Any, Literal, NamedTuple, NotRequired, TypeAlias, TypedDict +from typing import Any, Literal, NamedTuple, TypeAlias, TypedDict class JSONRPCError(enum.Enum): @@ -49,9 +49,9 @@ class JobFields(TypedDict): class CollectionUpdateParams(TypedDict): msg: str collection: str - id: NotRequired[Any] - fields: NotRequired[JobFields] - extra: NotRequired[dict] + id: Any + fields: JobFields + extra: dict class CollectionUpdate(TypedDict): @@ -62,7 +62,7 @@ class CollectionUpdate(TypedDict): TruenasTraceback = TypedDict('TruenasTraceback', { 'class': str, - 'frames': NotRequired[list[dict[str, Any]]], + 'frames': list[dict[str, Any]], 'formatted': str, 'repr': str, }) @@ -75,7 +75,7 @@ class TruenasError(TypedDict): reason: str trace: TruenasTraceback | None extra: list[ErrorExtra] - py_exception: NotRequired[str] + py_exception: str class NotifyUnsubscribedParams(TypedDict): diff --git a/truenas_api_client/legacy.py b/truenas_api_client/legacy.py index 60ab72b..5a42a8b 100644 --- a/truenas_api_client/legacy.py +++ b/truenas_api_client/legacy.py @@ -182,6 +182,7 @@ def result(self): job['error'], trace={ 'class': job['exc_info']['type'], + 'frames': [], 'formatted': job['exception'], 'repr': job['exc_info'].get('repr', job['exception'].splitlines()[-1]), },