Skip to content

Commit 6698c48

Browse files
committed
Convert values to ints and floats in keyval
1 parent a76f21d commit 6698c48

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

python/grass/experimental/tools.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ def json(self):
2626

2727
@property
2828
def keyval(self):
29-
# TODO: possibly use or add _text_to_key_value_dict
30-
# which converts int and float automatically
31-
return gs.parse_key_val(self._stdout)
29+
def conversion(value):
30+
try:
31+
return int(value)
32+
except ValueError:
33+
pass
34+
try:
35+
return float(value)
36+
except ValueError:
37+
pass
38+
return value
39+
40+
return gs.parse_key_val(self._stdout, val_type=conversion)
3241

3342
@property
3443
def comma_items(self):

0 commit comments

Comments
 (0)