diff --git a/qutebrowser/test/utils/usertypes/test_enum.py b/qutebrowser/test/utils/usertypes/test_enum.py index cc835eb81..90cacda8c 100644 --- a/qutebrowser/test/utils/usertypes/test_enum.py +++ b/qutebrowser/test/utils/usertypes/test_enum.py @@ -56,6 +56,12 @@ class EnumTests(TestCase): with self.assertRaises(KeyError): _ = self.enum['two'] + def test_start(self): + """Test the start= argument.""" + e = enum('three', 'four', start=3) + self.assertEqual(e.three, 3) + self.assertEqual(e.four, 4) + if __name__ == '__main__': unittest.main() diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 0ce154b54..53972bafe 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -32,7 +32,7 @@ from qutebrowser.utils.log import misc as logger _UNSET = object() -def enum(*items, **named): +def enum(*items, start=0): """Factory for simple enumerations. We really don't need more complex things here, so we don't use python3.4's @@ -42,9 +42,10 @@ def enum(*items, **named): Args: *items: Items to be sequentally enumerated. - **named: Items to have a given position/number. + start: The number to use for the first value. """ - enums = dict(zip(items, range(len(items))), **named) + numbers = range(start, len(items) + start) + enums = dict(zip(items, numbers)) return EnumBase('Enum', (), enums)