changed UndefinedUnitError to inherit from AttributeError, so `hasattr` works on unit registry.

This commit is contained in:
Johan Hidding 2017-02-27 15:52:44 +01:00
parent de8fdff91b
commit 1cac87cf60
2 changed files with 3 additions and 3 deletions

View File

@ -49,12 +49,12 @@ class RedefinitionError(ValueError):
return msg
class UndefinedUnitError(ValueError):
class UndefinedUnitError(AttributeError):
"""Raised when the units are not defined in the unit registry.
"""
def __init__(self, unit_names):
super(ValueError, self).__init__()
super(UndefinedUnitError, self).__init__()
self.unit_names = unit_names
def __str__(self):

View File

@ -234,7 +234,7 @@ class TestIssues(QuantityTestCase):
for func in (ureg.get_name, ureg.parse_expression):
val = func('meter')
self.assertRaises(ValueError, func, 'METER')
self.assertRaises(AttributeError, func, 'METER')
self.assertEqual(val, func('METER', False))
def test_issue104(self):