Skip to content

Commit 337a7fb

Browse files
toofardaerich
authored andcommitted
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: qutebrowser#7990
1 parent c397675 commit 337a7fb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

qutebrowser/browser/webengine/webenginesettings.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ class _SettingsWrapper:
5050
For read operations, the default profile value is always used.
5151
"""
5252

53+
def default_profile(self):
54+
assert default_profile is not None
55+
return default_profile
56+
5357
def _settings(self):
54-
yield default_profile.settings()
58+
yield self.default_profile().settings()
5559
if private_profile:
5660
yield private_profile.settings()
5761

@@ -76,19 +80,19 @@ def setUnknownUrlSchemePolicy(self, policy):
7680
settings.setUnknownUrlSchemePolicy(policy)
7781

7882
def testAttribute(self, attribute):
79-
return default_profile.settings().testAttribute(attribute)
83+
return self.default_profile().settings().testAttribute(attribute)
8084

8185
def fontSize(self, fonttype):
82-
return default_profile.settings().fontSize(fonttype)
86+
return self.default_profile().settings().fontSize(fonttype)
8387

8488
def fontFamily(self, which):
85-
return default_profile.settings().fontFamily(which)
89+
return self.default_profile().settings().fontFamily(which)
8690

8791
def defaultTextEncoding(self):
88-
return default_profile.settings().defaultTextEncoding()
92+
return self.default_profile().settings().defaultTextEncoding()
8993

9094
def unknownUrlSchemePolicy(self):
91-
return default_profile.settings().unknownUrlSchemePolicy()
95+
return self.default_profile().settings().unknownUrlSchemePolicy()
9296

9397

9498
class WebEngineSettings(websettings.AbstractSettings):
@@ -341,7 +345,10 @@ def _init_user_agent_str(ua):
341345

342346

343347
def init_user_agent():
344-
_init_user_agent_str(QWebEngineProfile.defaultProfile().httpUserAgent())
348+
"""Make the default WebEngine user agent available via parsed_user_agent."""
349+
actual_default_profile = QWebEngineProfile.defaultProfile()
350+
assert actual_default_profile is not None
351+
_init_user_agent_str(actual_default_profile.httpUserAgent())
345352

346353

347354
def _init_profile(profile: QWebEngineProfile) -> None:

0 commit comments

Comments
 (0)