Skip to content

Commit

Permalink
create undefined singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorcary committed Aug 19, 2024
1 parent e49c110 commit d74d208
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions truenas_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
CollectionUpdateParams, ErrorExtra, ErrorObj, JobFields, JSONRPCError, JSONRPCMessage, TruenasError,
TruenasTraceback
)
from .utils import MIDDLEWARE_RUN_DIR, ProgressBar, undefined
from .utils import MIDDLEWARE_RUN_DIR, ProgressBar, undefined, UndefinedType
try:
from libzfs import Error as ZFSError
except ImportError:
Expand Down Expand Up @@ -458,7 +458,7 @@ class Client:
"""
def __init__(self, uri: str | None=None, reserved_ports=False, py_exceptions=False, log_py_exceptions=False,
call_timeout: float=undefined, verify_ssl=True):
call_timeout: float | UndefinedType=undefined, verify_ssl=True):
"""Initialize a `Client`.
Args:
Expand Down Expand Up @@ -726,7 +726,7 @@ def _jobs_subscribe(self):

def call(self, method: str, *params, background=False, callback: _JobCallback | None=None,
job: Literal['RETURN'] | bool=False, register_call: bool | None=None,
timeout: float=undefined) -> Any:
timeout: float | UndefinedType=undefined) -> Any:
"""The primary way to send call requests to the API.
Send a JSON-RPC v2.0 Request to the server.
Expand Down Expand Up @@ -781,7 +781,7 @@ def call(self, method: str, *params, background=False, callback: _JobCallback |
self._unregister_call(c)

def wait(self, c: Call, *, callback: _JobCallback | None=None, job: Literal['RETURN'] | bool=False,
timeout: float=undefined) -> Any:
timeout: float | UndefinedType=undefined) -> Any:
"""Wait for an API call to return and return its result.
Args:
Expand All @@ -804,7 +804,7 @@ def wait(self, c: Call, *, callback: _JobCallback | None=None, job: Literal['RET
timeout = self._call_timeout

try:
if not c.returned.wait(timeout):
if not c.returned.wait(timeout): # type: ignore
raise CallTimeout()

if c.error:
Expand Down
10 changes: 8 additions & 2 deletions truenas_api_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
"""
import sys

from typing import Any, TextIO, Mapping
from typing import Any, final, TextIO, Mapping


MIDDLEWARE_RUN_DIR = '/var/run/middleware'
undefined = -1

@final
class UndefinedType:
def __new__(cls):
if not hasattr(cls, '_instance'):
cls._instance = super().__new__(cls)
return cls._instance
undefined = UndefinedType()

class Struct:
"""Simpler wrapper to access using object attributes instead of keys.
Expand Down

0 comments on commit d74d208

Please sign in to comment.