From 62a40521789eab273415550ea741ed668b2e947e Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Tue, 15 Feb 2022 10:51:52 +0000 Subject: [PATCH] [Docs] Remove custom mock to fix autodoc typing errors If a libtorrent return type was specified e.g. def get_lt_status(self) -> 'lt.torrent_status' Even as a string autodoc_typehints module would raise and error: Handler for event 'autodoc-process-docstring' threw an exception (exception: getattr(): attribute name must be string) This was a result of using a custom mock in Sphinx autodoc config and this Mock object name or qualname returns an object instead of str. Testing with putting modules in autodoc_mock_imports again showed no issues so removing custom mock Ref: https://github.com/tox-dev/sphinx-autodoc-typehints/issues/220 --- docs/source/conf.py | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9c5853c73..0e4a41914 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -219,45 +219,13 @@ latex_documents = [ # Autodoc section # --------------- -class Mock: - - __all__ = [] - - def __init__(self, *args, **kwargs): - pass - - def __call__(self, *args, **kwargs): - return '' - - @classmethod - def __getattr__(cls, name): - if name in ('__file__', '__path__', 'xdg_config_home'): - return '/dev/null' - elif name[0] == name[0].upper(): - mock_type = type(name, (), {}) - mock_type.__module__ = __name__ - return mock_type - else: - return Mock() - - def __add__(self, other): - return other - - def __or__(self, __): - return Mock() - - -# Use custom mock as autodoc_mock_imports fails to handle these modules. -MOCK_MODULES = ['deluge._libtorrent', 'xdg', 'xdg.BaseDirectory'] - -for mod_name in MOCK_MODULES: - sys.modules[mod_name] = Mock() # Must add these for autodoc to import packages successfully builtins.__dict__['_'] = lambda x: x builtins.__dict__['_n'] = lambda s, p, n: s if n == 1 else p autodoc_mock_imports = [ + 'deluge._libtorrent', 'twisted', 'rencode', 'OpenSSL',