Skip to content

Commit

Permalink
Remove uses of functools.wraps for API methods
Browse files Browse the repository at this point in the history
- This was originally implemented for the benefit of documentation so
  the docstrings in the MixIn classes could be replicated in the
  "interactive" classes in the RTD docs.
- This was leading to issues in both mypy as well as pyright and
  generally doesn't seem like a proper use-case for `wraps`.
  • Loading branch information
rmartin16 committed Jul 18, 2024
1 parent f2f0ebe commit 3cebf9e
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 169 deletions.
1 change: 1 addition & 0 deletions docs/source/apidoc/log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Log
.. autoclass:: qbittorrentapi.log.Log
:members:
:undoc-members:
:special-members: __call__

.. autoclass:: qbittorrentapi.log.LogPeersList
:members:
Expand Down
1 change: 1 addition & 0 deletions docs/source/apidoc/rss.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RSS
.. autoclass:: qbittorrentapi.rss.RSS
:members:
:undoc-members:
:special-members: __call__
:exclude-members: rss, addFolder, addFeed, removeItem, moveItem, refreshItem, markAsRead, setRule, renameRule, removeRule, matchingArticles, setFeedURL

.. autoclass:: qbittorrentapi.rss.RSSitemsDictionary
Expand Down
1 change: 1 addition & 0 deletions docs/source/apidoc/sync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sync
.. autoclass:: qbittorrentapi.sync.Sync
:members:
:undoc-members:
:special-members: __call__

.. autoclass:: qbittorrentapi.sync.SyncMainDataDictionary
:members:
Expand Down
25 changes: 12 additions & 13 deletions src/qbittorrentapi/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import os
from functools import wraps
from json import dumps
from logging import Logger, getLogger
from typing import Any, AnyStr, Iterable, Mapping, Union
Expand Down Expand Up @@ -269,86 +268,86 @@ class Application(ClientCache[AppAPIMixIn]):
""" # noqa: E501

@property
@wraps(AppAPIMixIn.app_version)
def version(self) -> str:
"""Implements :meth:`~AppAPIMixIn.app_version`."""
return self._client.app_version()

@property
@wraps(AppAPIMixIn.app_web_api_version)
def web_api_version(self) -> str:
"""Implements :meth:`~AppAPIMixIn.app_web_api_version`."""
return self._client.app_web_api_version()

webapiVersion = web_api_version

@property
@wraps(AppAPIMixIn.app_build_info)
def build_info(self) -> BuildInfoDictionary:
"""Implements :meth:`~AppAPIMixIn.app_build_info`."""
return self._client.app_build_info()

buildInfo = build_info

@wraps(AppAPIMixIn.app_shutdown)
def shutdown(self, **kwargs: APIKwargsT) -> None:
"""Implements :meth:`~AppAPIMixIn.app_shutdown`."""
self._client.app_shutdown(**kwargs)

@property
@wraps(AppAPIMixIn.app_preferences)
def preferences(self) -> ApplicationPreferencesDictionary:
"""Implements :meth:`~AppAPIMixIn.app_preferences`."""
return self._client.app_preferences()

@preferences.setter
@wraps(AppAPIMixIn.app_set_preferences)
def preferences(self, value: Mapping[str, Any]) -> None:
"""Implements :meth:`~AppAPIMixIn.app_set_preferences`."""
self.set_preferences(prefs=value)

@wraps(AppAPIMixIn.app_set_preferences)
def set_preferences(
self,
prefs: Mapping[str, Any] | None = None,
**kwargs: APIKwargsT,
) -> None:
"""Implements :meth:`~AppAPIMixIn.app_set_preferences`."""
self._client.app_set_preferences(prefs=prefs, **kwargs)

setPreferences = set_preferences

@property
@wraps(AppAPIMixIn.app_default_save_path)
def default_save_path(self) -> str:
"""Implements :meth:`~AppAPIMixIn.app_default_save_path`."""
return self._client.app_default_save_path()

defaultSavePath = default_save_path

@property
@wraps(AppAPIMixIn.app_network_interface_list)
def network_interface_list(self) -> NetworkInterfaceList:
"""Implements :meth:`~AppAPIMixIn.app_network_interface_list`."""
return self._client.app_network_interface_list()

networkInterfaceList = network_interface_list

@wraps(AppAPIMixIn.app_network_interface_address_list)
def network_interface_address_list(
self,
interface_name: str = "",
**kwargs: APIKwargsT,
) -> NetworkInterfaceAddressList:
"""Implements :meth:`~AppAPIMixIn.app_network_interface_address_list`."""
return self._client.app_network_interface_address_list(
interface_name=interface_name,
**kwargs,
)

networkInterfaceAddressList = network_interface_address_list

@wraps(AppAPIMixIn.app_send_test_email)
def send_test_email(self) -> None:
"""Implements :meth:`~AppAPIMixIn.app_send_test_email`."""
self._client.app_send_test_email()

sendTestEmail = send_test_email

@wraps(AppAPIMixIn.app_get_directory_content)
def get_directory_content(
self,
directory_path: str | os.PathLike[AnyStr] | None = None,
) -> DirectoryContentList:
"""Implements :meth:`~AppAPIMixIn.app_get_directory_content`."""
return self._client.app_get_directory_content(directory_path=directory_path)

getDirectoryContent = get_directory_content
11 changes: 3 additions & 8 deletions src/qbittorrentapi/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from functools import wraps
from logging import Logger, getLogger
from types import TracebackType
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -161,23 +160,19 @@ class Authorization(ClientCache[AuthAPIMixIn]):
""" # noqa: E501

@property
# Starting in Python 3.11.9/3.12.4, Sphinx is erroring for wraps and property...
# WARNING: Failed to get a function signature for qbittorrentapi.auth.Authorization.is_logged_in: # noqa E501
# descriptor '__call__' for 'type' objects doesn't apply to a 'property' object
# Removing documentation for now...hoping this is resolved in the future...
# @wraps(AuthAPIMixIn.is_logged_in)
def is_logged_in(self) -> bool:
"""Implements :meth:`~AuthAPIMixIn.is_logged_in`."""
return self._client.is_logged_in

@wraps(AuthAPIMixIn.auth_log_in)
def log_in(
self,
username: str | None = None,
password: str | None = None,
**kwargs: APIKwargsT,
) -> None:
"""Implements :meth:`~AuthAPIMixIn.auth_log_in`."""
return self._client.auth_log_in(username=username, password=password, **kwargs)

@wraps(AuthAPIMixIn.auth_log_out)
def log_out(self, **kwargs: APIKwargsT) -> None:
"""Implements :meth:`~AuthAPIMixIn.auth_log_out`."""
return self._client.auth_log_out(**kwargs)
20 changes: 15 additions & 5 deletions src/qbittorrentapi/log.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from functools import wraps

from qbittorrentapi.app import AppAPIMixIn
from qbittorrentapi.definitions import (
APIKwargsT,
Expand Down Expand Up @@ -130,17 +128,17 @@ class Log(ClientCache[LogAPIMixIn]):

def __init__(self, client: LogAPIMixIn):
super().__init__(client=client)
self.main = Log._Main(client=client)
self._main = Log.Main(client=client)

@wraps(LogAPIMixIn.log_peers)
def peers(
self,
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogPeersList:
"""Implements :meth:`~LogAPIMixIn.log_peers`."""
return self._client.log_peers(last_known_id=last_known_id, **kwargs)

class _Main(ClientCache["LogAPIMixIn"]):
class Main(ClientCache["LogAPIMixIn"]):
def _api_call(
self,
normal: bool | None = None,
Expand Down Expand Up @@ -168,6 +166,7 @@ def __call__(
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogMainList:
"""Implements :meth:`~LogAPIMixIn.log_main`."""
return self._api_call(
normal=normal,
info=info,
Expand All @@ -182,20 +181,24 @@ def info(
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogMainList:
"""Implements :meth:`~LogAPIMixIn.log_main`."""
return self._api_call(last_known_id=last_known_id, **kwargs)

def normal(
self,
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogMainList:
"""Implements :meth:`~LogAPIMixIn.log_main` with ``info=False``."""
return self._api_call(info=False, last_known_id=last_known_id, **kwargs)

def warning(
self,
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogMainList:
"""Implements :meth:`~LogAPIMixIn.log_main` with ``info=False`` and
``normal=False``."""
return self._api_call(
info=False,
normal=False,
Expand All @@ -208,10 +211,17 @@ def critical(
last_known_id: str | int | None = None,
**kwargs: APIKwargsT,
) -> LogMainList:
"""Implements :meth:`~LogAPIMixIn.log_main` with ``info=False``,
``normal=False``, and ``warning=False``."""
return self._api_call(
info=False,
normal=False,
warning=False,
last_known_id=last_known_id,
**kwargs,
)

@property
def main(self) -> Log.Main:
"""Implements :meth:`~LogAPIMixIn.log_main`."""
return self._main
Loading

0 comments on commit 3cebf9e

Please sign in to comment.