jszopi / repESP

Reproducing molecular ESP from partial charges and more
GNU General Public License v3.0
6 stars 7 forks source link

docs: Use `sphinx-autodoc-typehints` instead of repeating types in docstrings #26

Open jszopi opened 5 years ago

jszopi commented 5 years ago

Using the sphinx-autodoc-typehints (or sphinx-autodoc-napoleon-typehints) extension would avoid the repetition between the type annotations and the docstrings.

It's also possible that it will better handle NewType and TypeVar annotations, which currently show as undocumentable stubs. I couldn't remove them (in favour of explanation in the docstrings of the respective classes) with the :exclude-members: directive, because it either doesn't understand class members or doesn't work with these annotations. Edit: TypeVar hasn't been implemented yet: https://github.com/agronholm/sphinx-autodoc-typehints/issues/39

jszopi commented 5 years ago

With sphinx-autodoc-typehints v1.3.0, I get the following output:

~/.local/lib/python3.7/site-packages/sphinx/ext/autodoc/inspector.py:117: RemovedInSphinx20Warning: formatargspec() is now deprecated.  Please use sphinx.util.inspect.Signature instead.
  RemovedInSphinx20Warning)
/.../repESP/__init__.py:docstring of repESP:7: WARNING: Bullet list ends without a blank line; unexpected unindent.
WARNING: Invalid type annotation found on <function __init__ at 0x7f90ce1a2620>. Ignored: NameError("name 'Mesh' is not defined")

Exception occurred:
  File "<string>", line 1, in <module>
NameError: name 'Mesh' is not defined
The full traceback has been saved in /tmp/sphinx-err-8cfncly7.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

This is probably this issue with the extension: https://github.com/agronholm/sphinx-autodoc-typehints/issues/22 . However, even without it there's a warning about the Mesh type, but I haven't tracked it to a particular usage of Mesh (it seems that it's due to a type annotation rather than use in docstring).

/.../repESP/repESP/__init__.py:docstring of repESP:7: WARNING: Bullet list ends without a blank line; unexpected unindent.
WARNING: Invalid type annotation found on <function __init__ at 0x7f9275f7b7b8>. Ignored: NameError("name 'Mesh' is not defined")
jszopi commented 5 years ago

With sphinx-autodoc-napoleon-typehints, which seems to be an unmaintained fork of the former, I simply get:

Extension error:
Could not import extension sphinx_autodoc_napoleon_typehints (exception: cannot import name 'GenericMeta' from 'typing' (/usr/lib/python3.7/typing.py))

where GenericMeta, despite https://github.com/python/typing/issues/335 being fixed a long time ago, doesn't seem to be part of Python v3.7.1.rc2 nor 3.8-dev as per the docs.

jszopi commented 5 years ago

Using the following versions:

Sphinx version: 1.8.1
Python version: 3.7.1rc1 (CPython)
Docutils version: 0.14 
Jinja2 version: 2.10