Fix flake8 complaints

This commit is contained in:
Árni Dagur 2020-04-26 23:17:41 -04:00 committed by Árni Dagur
parent 006458c94e
commit 764ec9c76b
3 changed files with 37 additions and 33 deletions

View File

@ -37,6 +37,7 @@ exclude = .*,__pycache__,resources.py
# (numpy-style)
# D413: Missing blank line after last section (not in pep257?)
# A003: Builtin name for class attribute (needed for overridden methods)
# W503: like break before binary operator
# W504: line break after binary operator
ignore =
B001,B008,B305,
@ -46,7 +47,7 @@ ignore =
P101,P102,P103,
D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413,
A003,
W504
W503, W504
min-version = 3.4.0
max-complexity = 12
per-file-ignores =

View File

@ -42,7 +42,7 @@ from qutebrowser.api.interceptor import ResourceType
logger = logging.getLogger("misc")
_ad_blocker = typing.cast(typing.Optional['BraveAdBlocker'], None)
_ad_blocker = typing.cast(typing.Optional["BraveAdBlocker"], None)
def _is_whitelisted_url(url: QUrl) -> bool:
@ -65,31 +65,33 @@ def _is_whitelisted_url(url: QUrl) -> bool:
return False
MAP_FROM_RESOURCE_TYPE_TO_STRING = {
ResourceType.main_frame: "main_frame",
ResourceType.sub_frame: "sub_frame",
ResourceType.stylesheet: "stylesheet",
ResourceType.script: "script",
ResourceType.image: "image",
ResourceType.font_resource: "font",
ResourceType.sub_resource: "sub_frame",
ResourceType.object: "object",
ResourceType.media: "media",
ResourceType.worker: "other",
ResourceType.shared_worker: "other",
ResourceType.prefetch: "other",
ResourceType.favicon: "image",
ResourceType.xhr: "xhr",
ResourceType.ping: "ping",
ResourceType.service_worker: "other",
ResourceType.csp_report: "csp_report",
ResourceType.plugin_resource: "other",
ResourceType.preload_main_frame: "other",
ResourceType.preload_sub_frame: "other",
ResourceType.unknown: "other",
}
def resource_type_to_string(resource_type: ResourceType) -> str:
MAP = {
ResourceType.main_frame: "main_frame",
ResourceType.sub_frame: "sub_frame",
ResourceType.stylesheet: "stylesheet",
ResourceType.script: "script",
ResourceType.image: "image",
ResourceType.font_resource: "font",
ResourceType.sub_resource: "sub_frame",
ResourceType.object: "object",
ResourceType.media: "media",
ResourceType.worker: "other",
ResourceType.shared_worker: "other",
ResourceType.prefetch: "other",
ResourceType.favicon: "image",
ResourceType.xhr: "xhr",
ResourceType.ping: "ping",
ResourceType.service_worker: "other",
ResourceType.csp_report: "csp_report",
ResourceType.plugin_resource: "other",
ResourceType.preload_main_frame: "other",
ResourceType.preload_sub_frame: "other",
ResourceType.unknown: "other",
}
return MAP.get(resource_type, "other")
return MAP_FROM_RESOURCE_TYPE_TO_STRING.get(resource_type, "other")
# TODO: Move this code somewhere so that `adblock.py` can make use of it too.

View File

@ -60,17 +60,18 @@ def ad_blocker_factory(config_tmpdir, data_tmpdir, download_stub, config_stub):
def test_dataset(ad_blocker_factory):
"""
In the data folder, we have a file called `adblock_dataset.tsv`, which
contains tuples of (url, source_url, type) in each line.
"""Run the ad-blocking logic on a bunch of urls.
Thus, this test is only meant to catch syntax errors and the like, not
In the data folder, we have a file called `adblock_dataset.tsv`, which
contains tuples of (url, source_url, type) in each line. We run these
through the ad blocker to see if we get any exceptions.
This test is only meant to catch syntax errors and the like, not
incorrectness in the adblocker. There are thus no assert statements.
"""
def dataset_type_to_enum(type_int: int) -> ResourceType:
"""
Translate
"""
"""Translate the dataset's encoding of a resource type to Qutebrowser's."""
if type_int == 0:
return ResourceType.unknown
elif type_int == 1: