Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
User committed Jul 1, 2023
1 parent 2d170c3 commit f92c5da
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion grab/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from pprint import pprint # pylint: disable=unused-import
from typing import Any

from .base import BaseClient
Expand Down
5 changes: 2 additions & 3 deletions grab/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def process_encoding(self, encoding: None | str = None) -> str:
return unicodec.detect_content_encoding(
self.get_body_chunk() or b"",
content_type_header=(
self.headers.get("Content-Type", None) if self.headers else None
self.headers.get("Content-Type") if self.headers else None
),
markup="xml" if self.document_type == "xml" else "html",
)
Expand Down Expand Up @@ -262,8 +262,7 @@ def rex_text(
if default is UNDEFINED:
raise DataNotFound("Regexp not found") from ex
return default
else:
return match.group(1)
return match.group(1)

def rex_search(
self,
Expand Down
5 changes: 2 additions & 3 deletions grab/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections.abc import Mapping, MutableMapping
from copy import copy
from typing import Any, TypedDict, cast
from typing import Any, TypedDict
from urllib.parse import urlencode

from urllib3.filepost import encode_multipart_formdata
Expand Down Expand Up @@ -139,10 +139,9 @@ def compile_request_data( # noqa: CCR001
"Request.body and Request.fields could not be set both"
)
if self.multipart:
req_body, content_type = encode_multipart_formdata( # type: ignore
req_body, content_type = encode_multipart_formdata(
self.fields
)
req_body = cast(bytes, req_body)
else:
req_body, content_type = (
urlencode(self.fields).encode(),
Expand Down
2 changes: 1 addition & 1 deletion grab/spider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def process_grab_proxy(self, task: Task, grab: Grab) -> None:
if self.proxy_auto_change:
self.change_active_proxy(task, grab)
if self.proxy:
raise Exception("Look like it is not called from tests")
raise RuntimeError("Look like it is not called from tests")
# grab.zzzz(
# proxy=self.proxy.get_address(),
# proxy_userpwd=self.proxy.get_userpwd(),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spider_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def task_page_valid(self, _doc: Document, _task: Task) -> None:
self.stat.inc("foo")

def task_page_fail(self, _doc: Document, _task: Task) -> None:
raise Exception("Shit happens!")
raise RuntimeError("Shit happens!")

self.server.add_response(Response(), count=2)
bot = TestSpider()
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def load_test_config() -> MutableMapping[str, Any]:
else:
for key, val in local_config.items():
if key in DEFAULT_CONFIG:
raise Exception("Invalid config key: {}".format(key))
raise KeyError("Invalid config key: {}".format(key))
config[key] = val
return config

Expand Down

0 comments on commit f92c5da

Please sign in to comment.