Bug
loads() uses json.loads(token) to coerce bare scalar tokens to native Python types. This correctly converts 42 → int, 3.14 → float, true → bool, null → None. However, json.loads rejects Infinity, -Infinity, and NaN with a ValueError, causing them to fall back to plain strings — inconsistent with numeric tokens of the same conceptual type.
Reproducer
import structprop
data = structprop.loads("x = Infinity\ny = NaN\nz = 3.14\n")
print(type(data["x"])) # <class 'str'> — unexpected
print(type(data["y"])) # <class 'str'> — unexpected
print(type(data["z"])) # <class 'float'> — expected
Expected behaviour
Infinity, -Infinity, and NaN should deserialize as float('inf'), float('-inf'), and float('nan') respectively, consistent with how other numeric literals are handled.
Suggested fix
Catch the ValueError from json.loads and attempt float(token) as a fallback before returning the token as a plain string:
try:
return json.loads(token)
except ValueError:
try:
return float(token)
except ValueError:
return token
Bug
loads()usesjson.loads(token)to coerce bare scalar tokens to native Python types. This correctly converts42→int,3.14→float,true→bool,null→None. However,json.loadsrejectsInfinity,-Infinity, andNaNwith aValueError, causing them to fall back to plain strings — inconsistent with numeric tokens of the same conceptual type.Reproducer
Expected behaviour
Infinity,-Infinity, andNaNshould deserialize asfloat('inf'),float('-inf'), andfloat('nan')respectively, consistent with how other numeric literals are handled.Suggested fix
Catch the
ValueErrorfromjson.loadsand attemptfloat(token)as a fallback before returning the token as a plain string: