summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-05-27 12:43:40 +0200
committerFlorian Bruhin <me@the-compiler.org>2020-05-27 12:43:40 +0200
commit8ab4133bfc5bae1656f74c87a56d2d5f45a1c788 (patch)
treeadbdaf67afdf86e56165ac8740b8f9e0ef24f7c6
parente8b0ce7597627a5b5312a214a84ff2aed9bcdfe0 (diff)
downloadqutebrowser-8ab4133bfc5bae1656f74c87a56d2d5f45a1c788.tar.gz
qutebrowser-8ab4133bfc5bae1656f74c87a56d2d5f45a1c788.zip
configtypes: Fix handling of Unset in _Numeric with bounds
-rw-r--r--qutebrowser/config/configtypes.py18
-rw-r--r--tests/unit/config/test_configtypes.py4
2 files changed, 17 insertions, 5 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py
index 6eec13293..cfcc5f13a 100644
--- a/qutebrowser/config/configtypes.py
+++ b/qutebrowser/config/configtypes.py
@@ -797,11 +797,16 @@ class _Numeric(BaseType): # pylint: disable=abstract-method
assert isinstance(bound, (int, float)), bound
return bound
- def _validate_bounds(self, value: typing.Union[None, int, float],
- suffix: str = '') -> None:
+ def _validate_bounds(
+ self,
+ value: typing.Union[None, int, float, usertypes.Unset],
+ suffix: str = ''
+ ) -> None:
"""Validate self.minval and self.maxval."""
if value is None:
return
+ elif isinstance(value, usertypes.Unset):
+ return
elif self.minval is not None and value < self.minval:
raise configexc.ValidationError(
value, "must be {}{} or bigger!".format(self.minval, suffix))
@@ -837,7 +842,10 @@ class Int(_Numeric):
self.to_py(intval)
return intval
- def to_py(self, value: typing.Optional[int]) -> typing.Optional[int]:
+ def to_py(
+ self,
+ value: typing.Union[None, int, usertypes.Unset]
+ ) -> typing.Union[None, int, usertypes.Unset]:
self._basic_py_validation(value, int)
self._validate_bounds(value)
return value
@@ -861,8 +869,8 @@ class Float(_Numeric):
def to_py(
self,
- value: typing.Union[None, int, float],
- ) -> typing.Union[None, int, float]:
+ value: typing.Union[None, int, float, usertypes.Unset],
+ ) -> typing.Union[None, int, float, usertypes.Unset]:
self._basic_py_validation(value, (int, float))
self._validate_bounds(value)
return value
diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py
index 18019fb4f..841892ef2 100644
--- a/tests/unit/config/test_configtypes.py
+++ b/tests/unit/config/test_configtypes.py
@@ -1047,6 +1047,10 @@ class TestInt:
converted = typ.from_str(text)
assert typ.to_str(converted) == text
+ def test_bounds_handling_unset(self, klass):
+ typ = klass(minval=1, maxval=2)
+ assert typ.to_py(usertypes.UNSET) is usertypes.UNSET
+
class TestFloat: