[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 <function process_docstring at 0x7f6c16c8ec10> 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
This commit is contained in:
parent
8ece036770
commit
62a4052178
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue