mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 00:40:01 +02:00
updating helper function
This commit is contained in:
parent
3440a632ad
commit
b6953251b9
@ -272,7 +272,6 @@ def get_nested_value_from_DataService_by_path_and_key(
|
|||||||
return current_data.get(key, None)
|
return current_data.get(key, None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def convert_arguments_to_hinted_types(
|
def convert_arguments_to_hinted_types(
|
||||||
args: dict[str, Any], type_hints: dict[str, Any]
|
args: dict[str, Any], type_hints: dict[str, Any]
|
||||||
) -> dict[str, Any] | str:
|
) -> dict[str, Any] | str:
|
||||||
@ -357,38 +356,34 @@ def parse_list_attr_and_index(attr_string: str) -> tuple[str, Optional[int]]:
|
|||||||
"""
|
"""
|
||||||
Parses an attribute string and extracts a potential list attribute name and its
|
Parses an attribute string and extracts a potential list attribute name and its
|
||||||
index.
|
index.
|
||||||
|
Logs an error if the index is not a valid digit.
|
||||||
|
|
||||||
This function examines the provided attribute string. If the string contains square
|
Args:
|
||||||
brackets, it assumes that it's a list attribute and the string within brackets is
|
attr_string (str):
|
||||||
the index of an element. It then returns the attribute name and the index as an
|
The attribute string to parse. Can be a regular attribute name (e.g.,
|
||||||
integer. If no brackets are present, the function assumes it's a regular attribute
|
'attr_name') or a list attribute with an index (e.g., 'list_attr[2]').
|
||||||
and returns the attribute name and None as the index.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
-----------
|
|
||||||
attr_string: str
|
|
||||||
The attribute string to parse. Can be a regular attribute name (e.g.
|
|
||||||
'attr_name') or a list attribute with an index (e.g. 'list_attr[2]').
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
--------
|
tuple[str, Optional[int]]:
|
||||||
tuple: (str, Optional[int])
|
A tuple containing the attribute name as a string and the index as an
|
||||||
A tuple containing the attribute name as a string and the index as an integer if
|
integer if present, otherwise None.
|
||||||
present, otherwise None.
|
|
||||||
|
|
||||||
Example:
|
Examples:
|
||||||
--------
|
>>> parse_attribute_and_index('list_attr[2]')
|
||||||
>>> parse_list_attr_and_index('list_attr[2]')
|
('list_attr', 2)
|
||||||
('list_attr', 2)
|
>>> parse_attribute_and_index('attr_name')
|
||||||
>>> parse_list_attr_and_index('attr_name')
|
('attr_name', None)
|
||||||
('attr_name', None)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
attr_name = attr_string
|
|
||||||
index = None
|
index = None
|
||||||
if "[" in attr_string and "]" in attr_string:
|
attr_name = attr_string
|
||||||
attr_name, idx = attr_string[:-1].split("[")
|
if "[" in attr_string and attr_string.endswith("]"):
|
||||||
index = int(idx)
|
attr_name, index_part = attr_string.split("[", 1)
|
||||||
|
index_part = index_part.rstrip("]")
|
||||||
|
if index_part.isdigit():
|
||||||
|
index = int(index_part)
|
||||||
|
else:
|
||||||
|
logger.error(f"Invalid index format in key: {attr_name}")
|
||||||
return attr_name, index
|
return attr_name, index
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user