Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add automatic conversion from string to int/float type #921

11 changes: 11 additions & 0 deletions src/debugpy/common/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import builtins
import json
import operator
import string
import numbers


JsonDecoder = json.JSONDecoder
Expand Down Expand Up @@ -106,6 +108,15 @@ def of_type(*classinfo, **kwargs):
def validate(value):
if (optional and value == ()) or isinstance(value, classinfo):
return value
elif (
isinstance(value, str)
and all(x in string.digits + "." for x in value)
giaco5988 marked this conversation as resolved.
Show resolved Hide resolved
and any(issubclass(x, numbers.Number) for x in classinfo)
):
try:
return int(value)
except ValueError:
return float(value)
giaco5988 marked this conversation as resolved.
Show resolved Hide resolved
else:
if not optional and value == ():
raise ValueError("must be specified")
Expand Down