From 0e3f6e6b87736bea34c6424021f01cbc07501efe Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 12 Feb 2020 13:51:42 +0100 Subject: 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 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) --- qutebrowser/config/configtypes.py | 5 ++++- tests/unit/config/test_configinit.py | 3 ++- 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 -- cgit v1.2.3-54-g00ecf