summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-11-12 12:52:10 +1300
committertoofar <toofar@spalge.com>2023-11-13 18:45:18 +1300
commit399c72a9fb58d204357b39da8c1191dd002dfb55 (patch)
tree9a4c177441b54557b4fe5502ec9ca46dcdaacc8d
parent54e3993a59e862d8d6776ed6f6dbc0eb86c2ce67 (diff)
downloadqutebrowser-399c72a9fb58d204357b39da8c1191dd002dfb55.tar.gz
qutebrowser-399c72a9fb58d204357b39da8c1191dd002dfb55.zip
Handle profile.settings() return type being optional
With PyQt6-WebEngine 6.6.0 some pointer return types are now wrapped in Optionals[]. In practice they should never be none though so I'm adding some low effort null checking in here. For the changes in `_SettingsWrapper` I'm not actually sure this is the best way to be resolving this. mypy was complaining that `settings()` might be None. How does asserting on the profile help? idk but that seems to make it happy. Even more weirdly, none of these getters I changed seemed to be used anywhere apart from tests. Except for getAttribute, that's used in webkit code. Also the whole thing is checking the global default profile, generally settings should be checked on the profile on the tab. So I think this might just be some old code? idk, I just want to make mypy happy. For the `init_user_agent()` change that was complaining about the profile maybe being None. ref: https://github.com/qutebrowser/qutebrowser/pull/7990
-rw-r--r--qutebrowser/browser/webengine/webenginesettings.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py
index d0b6b5beb..f84ac7ba2 100644
--- a/qutebrowser/browser/webengine/webenginesettings.py
+++ b/qutebrowser/browser/webengine/webenginesettings.py
@@ -50,8 +50,12 @@ class _SettingsWrapper:
For read operations, the default profile value is always used.
"""
+ def default_profile(self):
+ assert default_profile is not None
+ return default_profile
+
def _settings(self):
- yield default_profile.settings()
+ yield self.default_profile().settings()
if private_profile:
yield private_profile.settings()
@@ -76,19 +80,19 @@ class _SettingsWrapper:
settings.setUnknownUrlSchemePolicy(policy)
def testAttribute(self, attribute):
- return default_profile.settings().testAttribute(attribute)
+ return self.default_profile().settings().testAttribute(attribute)
def fontSize(self, fonttype):
- return default_profile.settings().fontSize(fonttype)
+ return self.default_profile().settings().fontSize(fonttype)
def fontFamily(self, which):
- return default_profile.settings().fontFamily(which)
+ return self.default_profile().settings().fontFamily(which)
def defaultTextEncoding(self):
- return default_profile.settings().defaultTextEncoding()
+ return self.default_profile().settings().defaultTextEncoding()
def unknownUrlSchemePolicy(self):
- return default_profile.settings().unknownUrlSchemePolicy()
+ return self.default_profile().settings().unknownUrlSchemePolicy()
class WebEngineSettings(websettings.AbstractSettings):
@@ -341,7 +345,10 @@ def _init_user_agent_str(ua):
def init_user_agent():
- _init_user_agent_str(QWebEngineProfile.defaultProfile().httpUserAgent())
+ """Make the default WebEngine user agent available via parsed_user_agent."""
+ actual_default_profile = QWebEngineProfile.defaultProfile()
+ assert actual_default_profile is not None
+ _init_user_agent_str(actual_default_profile.httpUserAgent())
def _init_profile(profile: QWebEngineProfile) -> None: