Skip to content

Commit

Permalink
run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Dec 14, 2024
1 parent bb3f8ca commit 3ef2244
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
20 changes: 9 additions & 11 deletions hondana/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,20 @@ async def _pages(
at_home_data = await self.get_at_home(ssl=ssl)
self._at_home_url = at_home_data.base_url

_pages = at_home_data.data_saver if data_saver else at_home_data.data
_actual_pages = _pages[start:] if end is None else _pages[start:end]
for i, url in enumerate(_actual_pages, start=1): # noqa: B007 # it gets used in the outer scope
pages = at_home_data.data_saver if data_saver else at_home_data.data
resolved_pages = pages[start:] if end is None else pages[start:end]
for i, url in enumerate(resolved_pages, start=1): # noqa: B007 # it gets used in the outer scope
route = Route(
"GET",
f"/{'data-saver' if data_saver else 'data'}/{at_home_data.hash}/{url}",
base=self._at_home_url,
)
LOGGER.debug("Attempting to download: %s", route.url)
_start = time.monotonic()
start_req = time.monotonic()
response: tuple[bytes, ClientResponse] = await self._http.request(route)
data, page_resp = response
_end = time.monotonic()
_total = _end - _start
end_req = time.monotonic()
total_req_secs = end_req - start_req
LOGGER.debug("Downloaded: %s", route.url)

if report and self._at_home_url != "https://uploads.mangadex.org":
Expand All @@ -608,7 +608,7 @@ async def _pages(
success=page_resp.status == 200,
cached=page_resp.headers.get("X-Cache", "").casefold() == "hit",
size=(page_resp.content_length or 0),
duration=int(_total * 1000),
duration=int(total_req_secs * 1000),
)

if page_resp.status != 200:
Expand Down Expand Up @@ -808,11 +808,9 @@ def errored_files(self) -> set[str]:
Set[:class:`str`]
The filenames of the failed uploads.
"""
_succeeded: set[str] = set()
for item in self.succeeded:
_succeeded.update(data["attributes"]["originalFileName"] for data in item["data"])
succeeded: set[str] = {data["attributes"]["originalFileName"] for item in self.succeeded for data in item["data"]}

return self._filenames ^ _succeeded
return self._filenames ^ succeeded


class ChapterUpload:
Expand Down
3 changes: 1 addition & 2 deletions hondana/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ async def get_my_feed(
include_external_url=include_external_url,
)

_extend: list[Chapter] = [Chapter(self._http, item) for item in data["data"]]
chapters.extend(_extend)
chapters.extend([Chapter(self._http, item) for item in data["data"]])

offset += inner_limit
if not data["data"] or offset >= 10_000 or limit is not None:
Expand Down
4 changes: 2 additions & 2 deletions hondana/manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def __init__(self, http: HTTPClient, payload: manga.MangaResponse) -> None:
self.id: str = payload["id"]
self._title: LocalizedString = self._attributes["title"]
self._description: LocalizedString = self._attributes["description"]
_related = payload.get("related", None)
self.relation_type: MangaRelationType | None = MangaRelationType(_related) if _related else None
related = payload.get("related", None)
self.relation_type: MangaRelationType | None = MangaRelationType(related) if related else None
self.alternate_titles: LocalizedString = {k: v for item in self._attributes["altTitles"] for k, v in item.items()} # pyright: ignore[reportAttributeAccessIssue] # TypedDict.items() is weird
self.locked: bool = self._attributes.get("isLocked", False)
self.links: manga.MangaLinks = self._attributes["links"]
Expand Down
8 changes: 4 additions & 4 deletions hondana/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def __init__(self, **kwargs: Order) -> None:
msg = "You must pass valid kwargs."
raise TypeError(msg)

_fmt: list[str] = []
fmt: list[str] = []
for name, value in kwargs.items():
if name in self.__slots__:
setattr(self, name, value.value)
else:
_fmt.append(name)
fmt.append(name)

if _fmt:
msg = f"You have passed invalid kwargs: {', '.join(_fmt)}"
if fmt:
msg = f"You have passed invalid kwargs: {', '.join(fmt)}"
raise TypeError(msg)

def __repr__(self) -> str:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def test_tag_descriptions(
sorted(raw_tags, key=operator.itemgetter("id")),
strict=True,
):
_description = tag._description # pyright: ignore[reportPrivateUsage] # sorry, need this for test purposes
_raw_descriptions = raw_tag["attributes"]["description"]
_raw_descriptions = _raw_descriptions or {}
_raw_description = dict(_raw_descriptions)
assert _description == _raw_description
description = tag._description # pyright: ignore[reportPrivateUsage] # sorry, need this for test purposes
raw_descriptions = raw_tag["attributes"]["description"]
raw_descriptions = raw_descriptions or {}
raw_description = dict(raw_descriptions)
assert description == raw_description


class TestQueryTags:
Expand Down

0 comments on commit 3ef2244

Please sign in to comment.