Repository: beetbox/confuse

Issue:
as_template does not convert float
If it encounters an integer, it will convert it to an integer type validator
https://github.com/beetbox/confuse/blob/5528e7ae70850be07ecaca25826c972c195ee90b/confuse.py#L1666-L1669

If it encounters a float, it throws an error
https://github.com/beetbox/confuse/blob/5528e7ae70850be07ecaca25826c972c195ee90b/confuse.py#L1682-L1683
```
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1665, in as_template
    return MappingTemplate(value)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1209, in __init__
    subtemplates[key] = as_template(typ)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1665, in as_template
    return MappingTemplate(value)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1209, in __init__
    subtemplates[key] = as_template(typ)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1665, in as_template
    return MappingTemplate(value)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1209, in __init__
    subtemplates[key] = as_template(typ)
  File "/usr/local/lib/python3.7/dist-packages/confuse.py", line 1693, in as_template
    raise ValueError(u'cannot convert to template: {0!r}'.format(value))
ValueError: cannot convert to template: 0.5
```

Discussion:

Patch:
diff --git a/confuse.py b/confuse.py
index 8d5d875..5ec3936 100644
--- a/confuse.py
+++ b/confuse.py
@@ -1681,6 +1681,8 @@ def as_template(value):
         return OneOf(value)
     elif value is float:
         return Number()
+    elif isinstance(value, float):
+        return Number(value)
     elif value is None:
         return Template()
     elif value is dict:


Test patch:
diff --git a/test/test_valid.py b/test/test_valid.py
index f1452f3..f5a520f 100644
--- a/test/test_valid.py
+++ b/test/test_valid.py
@@ -163,6 +163,11 @@ class AsTemplateTest(unittest.TestCase):
         self.assertIsInstance(typ, confuse.Number)
         self.assertEqual(typ.default, confuse.REQUIRED)
 
+    def test_concrete_float_as_template(self):
+        typ = confuse.as_template(2.)
+        self.assertIsInstance(typ, confuse.Number)
+        self.assertEqual(typ.default, 2.)
+
     def test_none_as_template(self):
         typ = confuse.as_template(None)
         self.assertIs(type(typ), confuse.Template)