Catch an extra error that could break util.convert

This commit is contained in:
Paulus Schoutsen 2016-02-21 11:23:16 -08:00
parent c3bb6d32aa
commit 7c6dcdb082
2 changed files with 2 additions and 1 deletions

View File

@ -57,7 +57,7 @@ def convert(value, to_type, default=None):
""" Converts value to to_type, returns default if fails. """
try:
return default if value is None else to_type(value)
except ValueError:
except (ValueError, TypeError):
# If value could not be converted
return default

View File

@ -53,6 +53,7 @@ class TestUtil(unittest.TestCase):
self.assertEqual(True, util.convert("True", bool))
self.assertEqual(1, util.convert("NOT A NUMBER", int, 1))
self.assertEqual(1, util.convert(None, int, 1))
self.assertEqual(1, util.convert(object, int, 1))
def test_ensure_unique_string(self):
""" Test ensure_unique_string. """