Handle PyQt WebEngine version strings being Optional

With PyQt6-WebEngine 6.6.0 some pointer return types are now wrapped in
Optionals[]. In practice they should never be None, we've been relying on them
being set for long enough.

`qWebEngineVersion()` and `qWebEngineChromiumVersion()` now are typed as
returning `Optional[str]`. In `from_api()` we can handle the
`chromium_version` being null, so pass that through, but we are depending on
the `qtwe_version` being set, so add an assert there.

ref: https://github.com/qutebrowser/qutebrowser/pull/7990
This commit is contained in:
toofar 2023-11-12 12:56:54 +13:00
parent 399c72a9fb
commit f83cf4f504
1 changed files with 4 additions and 2 deletions

View File

@ -686,7 +686,7 @@ class WebEngineVersions:
return cls._CHROMIUM_VERSIONS.get(minor_version)
@classmethod
def from_api(cls, qtwe_version: str, chromium_version: str) -> 'WebEngineVersions':
def from_api(cls, qtwe_version: str, chromium_version: Optional[str]) -> 'WebEngineVersions':
"""Get the versions based on the exact versions.
This is called if we have proper APIs to get the versions easily
@ -796,8 +796,10 @@ def qtwebengine_versions(*, avoid_init: bool = False) -> WebEngineVersions:
except ImportError:
pass # Needs QtWebEngine 6.2+ with PyQtWebEngine 6.3.1+
else:
qtwe_version = qWebEngineVersion()
assert qtwe_version is not None
return WebEngineVersions.from_api(
qtwe_version=qWebEngineVersion(),
qtwe_version=qtwe_version,
chromium_version=qWebEngineChromiumVersion(),
)