diff options
-rw-r--r-- | qutebrowser/config/configtypes.py | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index cfcc5f13a..61284c34e 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -82,7 +82,8 @@ BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True, _Completions = typing.Optional[typing.Iterable[typing.Tuple[str, str]]] _StrUnset = typing.Union[str, usertypes.Unset] -_StrUnsetNone = typing.Union[None, str, usertypes.Unset] +_UnsetNone = typing.Union[None, usertypes.Unset] +_StrUnsetNone = typing.Union[str, _UnsetNone] class ValidValues: @@ -797,11 +798,9 @@ 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, usertypes.Unset], - suffix: str = '' - ) -> None: + def _validate_bounds(self, + value: typing.Union[int, float, _UnsetNone], + suffix: str = '') -> None: """Validate self.minval and self.maxval.""" if value is None: return @@ -844,8 +843,8 @@ class Int(_Numeric): def to_py( self, - value: typing.Union[None, int, usertypes.Unset] - ) -> typing.Union[None, int, usertypes.Unset]: + value: typing.Union[int, _UnsetNone] + ) -> typing.Union[int, _UnsetNone]: self._basic_py_validation(value, int) self._validate_bounds(value) return value @@ -869,8 +868,8 @@ class Float(_Numeric): def to_py( self, - value: typing.Union[None, int, float, usertypes.Unset], - ) -> typing.Union[None, int, float, usertypes.Unset]: + value: typing.Union[int, float, _UnsetNone], + ) -> typing.Union[int, float, _UnsetNone]: self._basic_py_validation(value, (int, float)) self._validate_bounds(value) return value @@ -882,8 +881,8 @@ class Perc(_Numeric): def to_py( self, - value: typing.Union[None, float, int, str, usertypes.Unset] - ) -> typing.Union[None, float, int, usertypes.Unset]: + value: typing.Union[float, int, str, _UnsetNone] + ) -> typing.Union[float, int, _UnsetNone]: self._basic_py_validation(value, (float, int, str)) if isinstance(value, usertypes.Unset): return value @@ -1078,8 +1077,7 @@ class QtColor(BaseType): except ValueError: raise configexc.ValidationError(val, "must be a valid color value") - def to_py(self, value: _StrUnset) -> typing.Union[usertypes.Unset, - None, QColor]: + def to_py(self, value: _StrUnset) -> typing.Union[_UnsetNone, QColor]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -1362,8 +1360,7 @@ class QtFont(FontBase): else: # pragma: no cover font.setFamily(families.to_str(quote=False)) - def to_py(self, value: _StrUnset) -> typing.Union[usertypes.Unset, - None, QFont]: + def to_py(self, value: _StrUnset) -> typing.Union[_UnsetNone, QFont]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -1442,7 +1439,7 @@ class Regex(BaseType): def to_py( self, value: typing.Union[str, typing.Pattern[str], usertypes.Unset] - ) -> typing.Union[usertypes.Unset, None, typing.Pattern[str]]: + ) -> typing.Union[_UnsetNone, typing.Pattern[str]]: """Get a compiled regex from either a string or a regex object.""" self._basic_py_validation(value, (str, self._regex_type)) if isinstance(value, usertypes.Unset): @@ -1533,7 +1530,7 @@ class Dict(BaseType): def to_py( self, - value: typing.Union[typing.Dict, usertypes.Unset, None] + value: typing.Union[typing.Dict, _UnsetNone] ) -> typing.Union[typing.Dict, usertypes.Unset]: self._basic_py_validation(value, dict) if isinstance(value, usertypes.Unset): @@ -1732,8 +1729,7 @@ class Proxy(BaseType): def to_py( self, value: _StrUnset - ) -> typing.Union[usertypes.Unset, None, - QNetworkProxy, _SystemProxy, pac.PACFetcher]: + ) -> typing.Union[_UnsetNone, QNetworkProxy, _SystemProxy, pac.PACFetcher]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -1803,10 +1799,7 @@ class FuzzyUrl(BaseType): """A URL which gets interpreted as search if needed.""" - def to_py( - self, - value: _StrUnset - ) -> typing.Union[None, QUrl, usertypes.Unset]: + def to_py(self, value: _StrUnset) -> typing.Union[QUrl, _UnsetNone]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -1844,7 +1837,7 @@ class Padding(Dict): def to_py( # type: ignore[override] self, - value: typing.Union[usertypes.Unset, typing.Dict, None], + value: typing.Union[typing.Dict, _UnsetNone], ) -> typing.Union[usertypes.Unset, PaddingValues]: d = super().to_py(value) if isinstance(d, usertypes.Unset): @@ -1916,10 +1909,7 @@ class Url(BaseType): """A URL as a string.""" - def to_py( - self, - value: _StrUnset - ) -> typing.Union[usertypes.Unset, None, QUrl]: + def to_py(self, value: _StrUnset) -> typing.Union[_UnsetNone, QUrl]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -2033,7 +2023,7 @@ class Key(BaseType): def to_py( self, value: _StrUnset - ) -> typing.Union[usertypes.Unset, None, keyutils.KeySequence]: + ) -> typing.Union[_UnsetNone, keyutils.KeySequence]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value @@ -2057,7 +2047,7 @@ class UrlPattern(BaseType): def to_py( self, value: _StrUnset - ) -> typing.Union[usertypes.Unset, None, urlmatch.UrlPattern]: + ) -> typing.Union[_UnsetNone, urlmatch.UrlPattern]: self._basic_py_validation(value, str) if isinstance(value, usertypes.Unset): return value |