Skip to content

Commit

Permalink
expand URL typing
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed May 24, 2024
1 parent 51d2f04 commit 9c4965f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions musify/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def close(self) -> None:
"""Close the current session. No more requests will be possible once this has been called."""
await self.session.close()

async def request(self, method: str, url: str, **kwargs) -> dict[str, Any]:
async def request(self, method: str, url: str | URL, **kwargs) -> dict[str, Any]:
"""
Generic method for handling API requests with back-off on failed requests.
See :py:func:`request` for more arguments.
Expand Down Expand Up @@ -219,7 +219,7 @@ def log(
level=level, msg=f"{method.upper():<7}: {url:<{url_pad}} | {" | ".join(str(part) for part in log)}"
)

async def _log_response(self, response: ClientResponse, method: str, url: str) -> None:
async def _log_response(self, response: ClientResponse, method: str, url: str | URL) -> None:
"""Log the method, URL, response text, and response headers."""
response_headers = response.headers
if isinstance(response.headers, Mapping): # format headers if JSON
Expand Down Expand Up @@ -270,38 +270,38 @@ async def _response_as_json(response: ClientResponse) -> dict[str, Any]:
except (aiohttp.ContentTypeError, json.decoder.JSONDecodeError):
return {}

async def get(self, url: str, **kwargs) -> dict[str, Any]:
async def get(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a GET request."""
kwargs.pop("method", None)
return await self.request("get", url=url, **kwargs)

async def post(self, url: str, **kwargs) -> dict[str, Any]:
async def post(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a POST request."""
kwargs.pop("method", None)
return await self.request("post", url=url, **kwargs)

async def put(self, url: str, **kwargs) -> dict[str, Any]:
async def put(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a PUT request."""
kwargs.pop("method", None)
return await self.request("put", url=url, **kwargs)

async def delete(self, url: str, **kwargs) -> dict[str, Any]:
async def delete(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a DELETE request."""
kwargs.pop("method", None)
return await self.request("delete", url, **kwargs)

async def options(self, url: str, **kwargs) -> dict[str, Any]:
async def options(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends an OPTIONS request."""
kwargs.pop("method", None)
return await self.request("options", url=url, **kwargs)

async def head(self, url: str, **kwargs) -> dict[str, Any]:
async def head(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a HEAD request."""
kwargs.pop("method", None)
kwargs.setdefault("allow_redirects", False)
return await self.request("head", url=url, **kwargs)

async def patch(self, url: str, **kwargs) -> dict[str, Any]:
async def patch(self, url: str | URL, **kwargs) -> dict[str, Any]:
"""Sends a PATCH request."""
kwargs.pop("method", None)
return await self.request("patch", url=url, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions musify/libraries/remote/spotify/api/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _sort_results(
results.sort(key=lambda result: id_list.index(result[self.id_key]))

async def _get_items_from_cache(
self, method: str, url: str, id_list: Collection[str]
self, method: str, url: str | URL, id_list: Collection[str]
) -> tuple[list[dict[str, Any]], Collection[str], Collection[str]]:
"""
Attempt to find the given ``id_list`` in the cache of the request handler and return results.
Expand Down Expand Up @@ -101,7 +101,7 @@ async def _get_items_from_cache(

async def _get_items_multi(
self,
url: str,
url: str | URL,
id_list: Collection[str],
params: Mapping[str, Any] | None = None,
key: str | None = None,
Expand Down Expand Up @@ -157,7 +157,7 @@ async def _get_items_multi(

async def _get_items_batched(
self,
url: str,
url: str | URL,
id_list: Collection[str],
params: Mapping[str, Any] | None = None,
key: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion musify/processors/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _pause(self, items: Iterable[MusifyItem], not_queried: Collection[MusifyItem

def as_dict(self) -> dict[str, Any]:
return {
"urls": self.urls,
"urls": [str(url) for url in self.urls],
"fields": [field.name.lower() for field in self.fields],
"interval": self.interval,
}

0 comments on commit 9c4965f

Please sign in to comment.