Skip to content

Commit a5ef5ce

Browse files
committed
Improve type conversion function
1 parent 8a40096 commit a5ef5ce

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sonar/utilities.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ def redacted_token(token: str) -> str:
159159
return re.sub(r"(..).*(..)", r"\1***\2", token)
160160

161161

162-
def convert_to_type(value: Any) -> Any:
162+
def convert_to_type(value: str) -> Any:
163163
"""Converts a potentially string value to the corresponding int or float"""
164+
if not isinstance(value, str):
165+
return value
164166
try:
165167
return int(value)
166168
except ValueError:
@@ -169,6 +171,10 @@ def convert_to_type(value: Any) -> Any:
169171
return float(value)
170172
except ValueError:
171173
pass
174+
try:
175+
return bool(value)
176+
except ValueError:
177+
pass
172178
return value
173179

174180

0 commit comments

Comments
 (0)