summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-02-12 13:51:42 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-02-13 12:06:35 +0100
commit0e3f6e6b87736bea34c6424021f01cbc07501efe (patch)
tree8fa215a0a1d0486799f5481fc3e48d1eb6be0117
parent303bc0217526f44790a3c4f267a8d5c2d579c3cf (diff)
downloadqutebrowser-0e3f6e6b87736bea34c6424021f01cbc07501efe.tar.gz
qutebrowser-0e3f6e6b87736bea34c6424021f01cbc07501efe.zip
Fix initializing of configtypes.QtFont when default_size is None
When initially reading a config.py and trying to validate QtFont values, Font.default_size is still set to None. This is because it needs to be initialized later in _late_init, as doing so requires a QApplication. This results in the following error while running config.py: Traceback (most recent call last): File "/usr/lib/python3.8/site-packages/qutebrowser/config/configfiles.py", line 731, in read_config_py exec(code, module.__dict__) File ".../.config/qutebrowser/config.py", line 52, in <module> c.fonts.debug_console = 'default_size default_family' File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 611, in __setattr__ self._config.set_obj(name, value, pattern=self._pattern) File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 457, in set_obj self._set_value(opt, value, pattern=pattern, File "/usr/lib/python3.8/site-packages/qutebrowser/config/config.py", line 317, in _set_value opt.typ.to_py(value) # for validation File "/usr/lib/python3.8/site-packages/qutebrowser/config/configtypes.py", line 1336, in to_py if size.lower().endswith('pt'): AttributeError: 'NoneType' object has no attribute 'lower' Similarly to what's done for configtypes.Font, assume that a None size is fine. Note that the default_size setting already gets validated via a separate regex anyways. Our tests didn't catch this because the init_patch patching already set default_size to a non-None value. While this makes sense for the rest of the tests, in test_configinit we really should have the real default value. Fixes #5223 (cherry picked from commit d68f484b6d003e5708fe390a921175c6c7777641)
-rw-r--r--qutebrowser/config/configtypes.py5
-rw-r--r--tests/unit/config/test_configinit.py3
2 files changed, 6 insertions, 2 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py
index 7c68ae964..4c2d458c3 100644
--- a/qutebrowser/config/configtypes.py
+++ b/qutebrowser/config/configtypes.py
@@ -1333,7 +1333,10 @@ class QtFont(Font):
if size == 'default_size':
size = self.default_size
- if size.lower().endswith('pt'):
+ if size is None:
+ # initial validation before default_size is set up.
+ pass
+ elif size.lower().endswith('pt'):
font.setPointSizeF(float(size[:-2]))
elif size.lower().endswith('px'):
font.setPixelSize(int(size[:-2]))
diff --git a/tests/unit/config/test_configinit.py b/tests/unit/config/test_configinit.py
index f461e4012..2063f6c13 100644
--- a/tests/unit/config/test_configinit.py
+++ b/tests/unit/config/test_configinit.py
@@ -41,7 +41,7 @@ def init_patch(qapp, fake_save_manager, monkeypatch, config_tmpdir,
monkeypatch.setattr(config, 'change_filters', [])
monkeypatch.setattr(configinit, '_init_errors', None)
monkeypatch.setattr(configtypes.Font, 'default_family', None)
- monkeypatch.setattr(configtypes.Font, 'default_size', '10pt')
+ monkeypatch.setattr(configtypes.Font, 'default_size', None)
yield
try:
objreg.delete('config-commands')
@@ -356,6 +356,7 @@ class TestLateInit:
"""Ensure setting fonts.default_family at init works properly.
See https://github.com/qutebrowser/qutebrowser/issues/2973
+ and https://github.com/qutebrowser/qutebrowser/issues/5223
"""
if method == 'temp':
args.temp_settings = settings