diff options
author | Árni Dagur <arni@dagur.eu> | 2020-11-06 11:57:09 +0000 |
---|---|---|
committer | Árni Dagur <arni@dagur.eu> | 2020-12-19 20:29:51 +0000 |
commit | 01d1d1494411380d97cac14614a829d3a69cecaf (patch) | |
tree | 79c8f24adeca0bcb0106c610587b10828018b84f /qutebrowser/components | |
parent | 71451483f4f380c2f70f6e5b28025af79b1168e5 (diff) | |
download | qutebrowser-01d1d1494411380d97cac14614a829d3a69cecaf.tar.gz qutebrowser-01d1d1494411380d97cac14614a829d3a69cecaf.zip |
Tackle code review
Diffstat (limited to 'qutebrowser/components')
-rw-r--r-- | qutebrowser/components/braveadblock.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/qutebrowser/components/braveadblock.py b/qutebrowser/components/braveadblock.py index 36b7f481e..e60a5a0ef 100644 --- a/qutebrowser/components/braveadblock.py +++ b/qutebrowser/components/braveadblock.py @@ -44,14 +44,9 @@ try: except ImportError: adblock = None # type: ignore[assignment] +# If the `adblock` library version is outdated, this variable is not None and +# contains its version. _outdated_version: Optional[str] = None -if adblock is not None: - _adblock_info = version.MODULE_INFO["adblock"] - if _adblock_info.is_outdated(): - adblock = None # type: ignore[assignment] - _outdated_version = _adblock_info.get_version() - - logger = logging.getLogger("network") ad_blocker: Optional["BraveAdBlocker"] = None @@ -78,7 +73,7 @@ def _possibly_show_missing_dependency_warning() -> None: message.warning( f"Installed version {_outdated_version} of the" " 'adblock' dependency is too old. Minimum supported is" - f" {_adblock_info.min_version}." + f" {version.MODULE_INFO['adblock'].min_version}." ) else: message.warning( @@ -286,11 +281,19 @@ def on_method_changed() -> None: def init(context: apitypes.InitContext) -> None: """Initialize the Brave ad blocker.""" global ad_blocker + global adblock + global _outdated_version + + if adblock is not None: + _adblock_info = version.MODULE_INFO["adblock"] + if _adblock_info.is_outdated(): + adblock = None # type: ignore[assignment] + _outdated_version = _adblock_info.get_version() if adblock is None: # We want 'adblock' to be an optional dependency. If the module is - # not found, we simply set the `ad_blocker` global to `None`. Always - # remember to check the case where `ad_blocker` is `None`! + # not installed or is outdated, we simply set the `ad_blocker` global to + # `None`. ad_blocker = None # type: ignore[unreachable] _possibly_show_missing_dependency_warning() return |