Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-130887 / 25.04 / Remove typing.NotRequired for Python 3.10 compatibility #11

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pytype.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "pytype"
name: 'pytype'

on:
pull_request:
Expand All @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
install_requires=[
"websocket-client",
],
python_requires=">=3.10",
entry_points={
"console_scripts": [
"midclt = truenas_api_client:main",
Expand Down
25 changes: 16 additions & 9 deletions truenas_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]),
},
Expand All @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions truenas_api_client/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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,
})
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions truenas_api_client/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
},
Expand Down
Loading