Skip to content

Method based Parameter.<get/set>_value API #21

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
41 changes: 40 additions & 1 deletion pycsh.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ These provide an object-oriented interface to libparam, but are largely meant fo

from __future__ import annotations

from warnings import deprecated as _deprecated
from _typeshed import Self
from typing import \
Any as _Any, \
Iterable as _Iterable, \
Literal as _Literal, \
Callable as _Callable
Callable as _Callable, \
Sequence as _Sequence
from datetime import datetime as _datetime

_param_value_hint = int | float | str
Expand Down Expand Up @@ -129,13 +131,15 @@ class Parameter:
""" Returns the best Python representation type object of the param_t c struct type. i.e int for uint32. """

@property
@_deprecated("Use .get_value(..., remote=False) instead")
def cached_value(self) -> int | float:
"""
Returns the local cached value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""

@cached_value.setter
@_deprecated("Use .set_value(..., remote=False) instead")
def cached_value(self, value: int | float) -> None:
"""
Sets the local cached value of the parameter.
Expand All @@ -144,20 +148,35 @@ class Parameter:
"""

@property
@_deprecated("Use .get_value() instead")
def remote_value(self) -> int | float:
"""
Returns the remote value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""

@remote_value.setter
@_deprecated("Use .set_value() instead")
def remote_value(self, value: int | float) -> None:
"""
Sets the remote value of the parameter.

:param value: New desired value. Assignments to other parameters, use their value instead, Otherwise uses .__str__().
"""

def set_value(self, value: _param_value_hint, remote=True, timeout: int = None) -> None:
"""
Sets the remote value of the parameter.

:raises ConnectionError: When no response is received.
"""

def get_value(self, remote=True, timeout: int = None) -> _param_value_hint:
"""
Returns the remote value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""

@property
def is_vmem(self) -> bool:
""" Returns True or False based on whether the parameter is a vmem parameter. """
Expand Down Expand Up @@ -231,13 +250,15 @@ class ParameterArray(Parameter):
"""

@property
@_deprecated("Use .get_value(..., remote=False) instead")
def cached_value(self) -> str | tuple[int | float]:
"""
Returns the local cached value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""

@cached_value.setter
@_deprecated("Use .set_value(..., remote=False) instead")
def cached_value(self, value: str | _Iterable[int | float]) -> None:
"""
Sets the local cached value of the parameter.
Expand All @@ -246,20 +267,35 @@ class ParameterArray(Parameter):
"""

@property
@_deprecated("Use .get_value() instead")
def remote_value(self) -> str | tuple[int | float]:
"""
Returns the remote value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""

@remote_value.setter
@_deprecated("Use .set_value() instead")
def remote_value(self, value: str | _Iterable[int | float]) -> None:
"""
Sets the remote value of the parameter.

:param value: New desired value. Assignments to other parameters, use their value instead, Otherwise uses .__str__().
"""

def set_value(self, value: _Sequence[_param_value_hint], remote=True, timeout: int = None) -> None:
"""
Sets the remote value of the parameter.

:raises ConnectionError: When no response is received.
"""

def get_value(self, remote=True, timeout: int = None) -> tuple[_param_value_hint, ...]:
"""
Returns the remote value of the parameter from its specified node in the Python representation of its type.
Array parameters return a tuple of values, whereas normal parameters return only a single value.
"""


class PythonParameter(Parameter):
""" Parameter created in Python. """
Expand Down Expand Up @@ -312,6 +348,9 @@ class PythonParameter(Parameter):
Change the callback of the parameter
"""

# TODO Kevin: PythonParameter(s) are never remote, so they should not have a get/set_value(remote=) argument. So we would need a RemoteParameter subclass


class PythonArrayParameter(PythonParameter, ParameterArray):
""" ParameterArray created in Python. """

Expand Down