From cc5083543fb247eefdc579498d2ec91193afe9f2 Mon Sep 17 00:00:00 2001 From: Marcus <77537491+MarzaElise@users.noreply.github.com> Date: Sun, 26 Sep 2021 14:55:34 +0530 Subject: [PATCH] Fix issue #7 --- holybooks/bible.py | 14 ++----------- holybooks/errors.py | 4 +++- holybooks/quran.py | 50 ++++++++------------------------------------- 3 files changed, 14 insertions(+), 54 deletions(-) diff --git a/holybooks/bible.py b/holybooks/bible.py index d1fb839..9d096ab 100644 --- a/holybooks/bible.py +++ b/holybooks/bible.py @@ -1,4 +1,6 @@ from .errors import ApiError, NotFound +import aiohttp +import requests __all__ = ("ChapterVerse", "Bible") @@ -45,12 +47,6 @@ def request( starting_verse: int, ending_verse: int = None, ): - try: - import requests - except ImportError: - raise ImportError( - "Please Install the requests module if you want to make a sync request." - ) self = cls(book) verse = _build_verse(starting_verse, ending_verse) @@ -84,12 +80,6 @@ async def async_request( ending_verse: int = None, loop=None, ): - try: - import aiohttp - except ImportError: - raise ImportError( - "Please Install the aiohttp module if you want to make an async request." - ) self = cls(book) verse = _build_verse(starting_verse, ending_verse) diff --git a/holybooks/errors.py b/holybooks/errors.py index c3f81be..2772faf 100644 --- a/holybooks/errors.py +++ b/holybooks/errors.py @@ -1,5 +1,7 @@ from typing import TYPE_CHECKING -from typing import Optional, Union + +if TYPE_CHECKING: + from typing import Optional, Union __all__ = ( "ApiError", diff --git a/holybooks/quran.py b/holybooks/quran.py index 7ead2df..c5a399b 100644 --- a/holybooks/quran.py +++ b/holybooks/quran.py @@ -1,5 +1,11 @@ -from typing import Union, Optional from .errors import ApiError, WrongLang, NumberError, ContentTypeError +import aiohttp +import requests +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from typing import Union, Optional + __all__ = ( "Surah", @@ -19,12 +25,6 @@ def __init__(self, surah: int = None): @classmethod def request(cls, surah: int = None): - try: - import requests - except ImportError: - raise ImportError( - "Please Install the requests module if you want to make a sync request." - ) self = cls(surah) @@ -45,12 +45,6 @@ def request(cls, surah: int = None): @classmethod async def async_request(cls, surah: int = None, *, loop=None): - try: - import aiohttp - except ImportError: - raise ImportError( - "Please Install the aiohttp module if you want to make an async request." - ) self = cls(surah) @@ -185,13 +179,6 @@ def __init__(self, surah: int = None, *, ayah: int = None): @classmethod def request(cls, surah: int = None, *, ayah: int = None, loop=None): - try: - import requests - except ImportError: - raise ImportError( - "Please Install the requests module if you want to make a sync request." - ) - self = cls(surah, ayah=ayah) if not self._session: @@ -211,12 +198,6 @@ def request(cls, surah: int = None, *, ayah: int = None, loop=None): async def async_request( cls, surah: int = None, *, ayah: int = None, loop=None ): - try: - import aiohttp - except ImportError: - raise ImportError( - "Please Install the aiohttp module if you want to make an async request." - ) self = cls(surah, ayah=ayah) @@ -293,12 +274,6 @@ async def async_request( request: int = None, loop=None, ): - try: - import aiohttp - except ImportError: - raise ImportError( - "Please Install the aiohttp module if you want to make an async request." - ) self = cls(mention, surah=surah, request=request) @@ -336,12 +311,6 @@ def request( surah: Optional[Union[str, int]] = None, request: int = None, ): - try: - import requests - except ImportError: - raise ImportError( - "Please Install the requests module if you want to make a sync request." - ) self = cls(mention, surah=surah, request=request) @@ -381,15 +350,14 @@ def find(self): if self.data is None or self.matches is None: return None data = [] - if self.req == None: + if self.req is None: for num in range(self.data["count"]): data.append(self.matches[num]["text"]) - return data else: for num in range(self.req): data.append(self.matches[num]["text"]) - return data + return data def __enter__(self): return self