use try/except

This commit is contained in:
Raphael Deem 2017-06-26 21:26:34 -07:00
parent 4379a4b067
commit 395d85a12f

View File

@ -201,11 +201,10 @@ class Config(dict):
for k, v in os.environ.items():
if k.startswith(SANIC_PREFIX):
_, config_key = k.split(SANIC_PREFIX, 1)
# This is a float or an int
if v.replace('.', '').isdigit():
if '.' in v:
self[config_key] = float(v)
else:
try:
self[config_key] = int(v)
else:
except ValueError:
try:
self[config_key] = float(v)
except ValueError:
self[config_key] = v