Skip to content

Commit caf895a

Browse files
Bastian-KrauseEmantor
authored andcommitted
config: allow types other than string in get_option()/set_option()
There is no reason to limit options to strings. YAML supports scalars, lists and dictionaries. As there is no way to write the options set during runtime back to YAML, so there is no reason to limit the types for the set_option() method either. Lift this limitation, so YAML-supported data types can be retrieved and all data types can be set. Note that this changes previous behavior, because now options are not converted to strings anymore. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent a5b7163 commit caf895a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

labgrid/config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ def get_option(self, name, default=None):
142142
143143
Args:
144144
name (str): name of the option
145-
default (str): A default parameter in case the option can not be
145+
default (any): A default parameter in case the option can not be
146146
found
147147
148148
Returns:
149-
str: value of the option or default parameter
149+
any: value of the option or default parameter
150150
151151
Raises:
152152
KeyError: if the requested image can not be found in the
153153
configuration
154154
"""
155155
try:
156-
return str(self.data['options'][name])
156+
return self.data['options'][name]
157157
except KeyError:
158158
if default is None:
159159
raise KeyError(f"no option '{name}' found in configuration")
@@ -165,9 +165,8 @@ def set_option(self, name, value):
165165
166166
Args:
167167
name (str): name of the option
168-
value (str): the new value
168+
value (any): the new value
169169
"""
170-
assert isinstance(value, str)
171170
self.data.setdefault('options', {})[name] = value
172171

173172
def get_target_option(self, target, name, default=None):

0 commit comments

Comments
 (0)