From 4418d8c73b26639016733bc0a3264a96046c6ab1 Mon Sep 17 00:00:00 2001 From: JPFrancoia Date: Wed, 25 Dec 2019 17:11:09 +0100 Subject: Fixing mistakes related to type hinting. --- tpblite/models/utils.py | 6 +++--- tpblite/tpblite.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tpblite/models/utils.py b/tpblite/models/utils.py index dd03b55..6c479d4 100644 --- a/tpblite/models/utils.py +++ b/tpblite/models/utils.py @@ -1,4 +1,4 @@ -from typing import Tuple, TypeVar +from typing import Tuple, Type, TypeVar import random from urllib.request import Request, urlopen import urllib.error @@ -31,13 +31,13 @@ class QueryParser: @classmethod def search( - cls, query: str, base_url: str, page: int, order: int, category: int + cls: Type[T], query: str, base_url: str, page: int, order: int, category: int ) -> T: segments = ("search", query, str(page), str(order), str(category)) return cls(base_url, segments) @classmethod - def browse(cls, base_url: str, category: int, page: int, order: int) -> T: + def browse(cls: Type[T], base_url: str, category: int, page: int, order: int) -> T: # The 0 is added to the URL to stay consistent with the manual web request segments = ("browse", str(category), str(page), str(order), "0") return cls(base_url, segments) diff --git a/tpblite/tpblite.py b/tpblite/tpblite.py index e4a0c58..3c68d62 100644 --- a/tpblite/tpblite.py +++ b/tpblite/tpblite.py @@ -6,9 +6,6 @@ from .models.utils import QueryParser class TPB: - # PirateBay URL to use for queries - base_url: str - def __init__(self, base_url: str = "https://tpb.party"): """ThePirateBay Object @@ -16,6 +13,7 @@ class TPB: base_url (str): PirateBay URL to use for queries """ + # PirateBay URL to use for queries self.base_url = base_url # Compiled search string used to query the PirateBay URL @@ -26,7 +24,7 @@ class TPB: def search( self, query: str, page: int = 0, order: int = 99, category: int = 0 - ) -> Torrent: + ) -> Torrents: """Search ThePirateBay and return list of Torrents Args: @@ -36,14 +34,14 @@ class TPB: category TODO Return: - Torrent + Torrents """ - q = QueryParser.from_search(query, self.base_url, page, order, category) + q = QueryParser.search(query, self.base_url, page, order, category) self._search_url = q.url return Torrents(q.html_source) - def browse(self, category: int = 0, page: int = 0, order: int = 99) -> Torrent: + def browse(self, category: int = 0, page: int = 0, order: int = 99) -> Torrents: """Browse ThePirateBay and return list of Torrents Args: @@ -56,6 +54,6 @@ class TPB: Torrent """ - q = QueryParser.from_browse(self.base_url, category, page, order) + q = QueryParser.browse(self.base_url, category, page, order) self._search_url = q.url return Torrents(q.html_source) -- cgit v1.2.3