diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index c39fdceb7..632f2311c 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -120,10 +120,14 @@ class BaseType: value: The value to check. pytype: A Python type to check the value against. """ - if value is None and not self.none_ok: - raise configexc.ValidationError(value, "may not be null!") + if value is None: + if not self.none_ok: + raise configexc.ValidationError(value, "may not be null!") + else: + return - if value is not None and not isinstance(value, pytype): + if (not isinstance(value, pytype) or + pytype is int and isinstance(value, bool)): if isinstance(pytype, tuple): expected = ' or '.join(typ.__name__ for typ in pytype) else: @@ -132,7 +136,7 @@ class BaseType: value, "expected a value of type {} but got {}.".format( expected, type(value).__name__)) - if value is not None and isinstance(value, str): + if isinstance(value, str): self._basic_str_validation(value) def _basic_str_validation(self, value): diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index c1ca352e7..c15f2e09d 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -736,6 +736,7 @@ class TestInt: ({}, 2.5), ({}, 'foobar'), ({'minval': 2, 'maxval': 3}, 1), + ({}, True), ]) def test_from_py_invalid(self, klass, kwargs, val): with pytest.raises(configexc.ValidationError):