|
24 | 24 |
|
25 | 25 | import asyncio |
26 | 26 | import json |
27 | | -from typing import Awaitable, Callable, Optional, Union, TYPE_CHECKING |
| 27 | +from typing import TYPE_CHECKING, Awaitable, Callable, Optional, Type, Union |
| 28 | + |
28 | 29 | if TYPE_CHECKING: |
29 | 30 | import requests |
30 | 31 |
|
@@ -56,15 +57,15 @@ def __init__( |
56 | 57 | self, *, |
57 | 58 | api_key: str = None, |
58 | 59 | session: Optional[Union[aiohttp.ClientSession, |
59 | | - requests.Session]] = None |
| 60 | + Type["requests.Session"]]] = None |
60 | 61 | ) -> None: |
61 | 62 | self.api_key = api_key |
62 | 63 | self._are_we_async = session is None or isinstance( |
63 | 64 | session, aiohttp.ClientSession) |
64 | 65 | self.session = self._generate_sync_session( |
65 | 66 | session) if not self._are_we_async else None |
66 | 67 |
|
67 | | - def _generate_sync_session(self, session: requests.Session) -> requests.Session: |
| 68 | + def _generate_sync_session(self, session: Type["requests.Session"]) -> Type["requests.Session"]: |
68 | 69 | """ We will update a :class:`requests.Session` instance with the auth we require. """ |
69 | 70 | # the passed session was found to be 'sync'. |
70 | 71 | if self.api_key: |
@@ -100,7 +101,7 @@ def post(self, content: str, syntax: str = None) -> Union[Paste, Awaitable]: |
100 | 101 | def _perform_sync_post(self, content: str, syntax: str = None) -> Paste: |
101 | 102 | """ Sync post request. """ |
102 | 103 | payload = {'meta': [{'index': 0, 'syntax': syntax}]} |
103 | | - response: requests.Response = self.session.post(API_BASE_URL, files={ |
| 104 | + response: Type["requests.Response"] = self.session.post(API_BASE_URL, files={ |
104 | 105 | 'data': content, 'meta': (None, json.dumps(payload), 'application/json')}, timeout=CLIENT_TIMEOUT) |
105 | 106 | if response.status_code not in [200, 201]: |
106 | 107 | raise APIError(response.status_code, response.text) |
|
0 commit comments