mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-01-17 09:29:26 +01:00
removes unused code
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, get_type_hints
|
from typing import Any
|
||||||
|
|
||||||
import pydase.units as u
|
import pydase.units as u
|
||||||
from pydase.data_service.abstract_data_service import AbstractDataService
|
from pydase.data_service.abstract_data_service import AbstractDataService
|
||||||
@@ -10,7 +10,6 @@ from pydase.observer_pattern.observable.observable import (
|
|||||||
Observable,
|
Observable,
|
||||||
)
|
)
|
||||||
from pydase.utils.helpers import (
|
from pydase.utils.helpers import (
|
||||||
convert_arguments_to_hinted_types,
|
|
||||||
get_class_and_instance_attributes,
|
get_class_and_instance_attributes,
|
||||||
is_property_attribute,
|
is_property_attribute,
|
||||||
)
|
)
|
||||||
@@ -22,19 +21,8 @@ from pydase.utils.serialization.serializer import (
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def process_callable_attribute(attr: Any, args: dict[str, Any]) -> Any:
|
|
||||||
converted_args_or_error_msg = convert_arguments_to_hinted_types(
|
|
||||||
args, get_type_hints(attr)
|
|
||||||
)
|
|
||||||
return (
|
|
||||||
attr(**converted_args_or_error_msg)
|
|
||||||
if not isinstance(converted_args_or_error_msg, str)
|
|
||||||
else converted_args_or_error_msg
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DataService(AbstractDataService):
|
class DataService(AbstractDataService):
|
||||||
def __init__(self, **kwargs: Any) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._task_manager = TaskManager(self)
|
self._task_manager = TaskManager(self)
|
||||||
|
|
||||||
|
|||||||
@@ -63,49 +63,6 @@ def get_object_attr_from_path_list(target_obj: Any, path: list[str]) -> Any:
|
|||||||
return target_obj
|
return target_obj
|
||||||
|
|
||||||
|
|
||||||
def convert_arguments_to_hinted_types(
|
|
||||||
args: dict[str, Any], type_hints: dict[str, Any]
|
|
||||||
) -> dict[str, Any] | str:
|
|
||||||
"""
|
|
||||||
Convert the given arguments to their types hinted in the type_hints dictionary.
|
|
||||||
|
|
||||||
This function attempts to convert each argument in the args dictionary to the type
|
|
||||||
specified for the argument in the type_hints dictionary. If the conversion is
|
|
||||||
successful, the function replaces the original argument in the args dictionary with
|
|
||||||
the converted argument.
|
|
||||||
|
|
||||||
If a ValueError is raised during the conversion of an argument, the function logs
|
|
||||||
an error message and returns the error message as a string.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args: A dictionary of arguments to be converted. The keys are argument names
|
|
||||||
and the values are the arguments themselves.
|
|
||||||
type_hints: A dictionary of type hints for the arguments. The keys are
|
|
||||||
argument names and the values are the hinted types.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
A dictionary of the converted arguments if all conversions are successful,
|
|
||||||
or an error message string if a ValueError is raised during a conversion.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Convert arguments to their hinted types
|
|
||||||
for arg_name, arg_value in args.items():
|
|
||||||
if arg_name in type_hints:
|
|
||||||
arg_type = type_hints[arg_name]
|
|
||||||
if isinstance(arg_type, type):
|
|
||||||
# Attempt to convert the argument to its hinted type
|
|
||||||
try:
|
|
||||||
args[arg_name] = arg_type(arg_value)
|
|
||||||
except ValueError:
|
|
||||||
msg = (
|
|
||||||
f"Failed to convert argument '{arg_name}' to type "
|
|
||||||
f"{arg_type.__name__}"
|
|
||||||
)
|
|
||||||
logger.error(msg)
|
|
||||||
return msg
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
def update_value_if_changed(
|
def update_value_if_changed(
|
||||||
target: Any, attr_name_or_index: str | int, new_value: Any
|
target: Any, attr_name_or_index: str | int, new_value: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user