Search code examples
pythonpython-sphinxread-the-docs

Sphinx autodoc extension for python > 3.5 docstrings not working because of function argument types


I've been trying to make autodoc automatically document my python 3.7 module. The only file I need to get documented is the init.py file in one single module. That file consists of only functions and has docstrings in the Sphinx format. So far so good. However, my functions have their arguments types noted such as:

def func1(filepaths: list):
  ...

def log_custom_hyperparameter(model, param_name: str, param_value):
  ...

This is throwing off autodoc. I am getting the following error:

WARNING: autodoc: failed to import module u'<my_module>'; the following exception was raised:
Traceback (most recent call last):
  File "/Users/manjotpahwa/Library/Python/2.7/lib/python/site-packages/sphinx/ext/autodoc/importer.py", line 154, in import_module
    __import__(modname)
  File "/Users/manjotpahwa/<path to file>/__init__.py", line 9
    def log_code_files(filepaths: list):
                                ^
SyntaxError: invalid syntax

Does autodoc not support parsing python files > python 3.5?

Thanks


Solution

  • Actually I think I found out the answer to this question. Turns out my sphinx was using python 2.7 site packages. This helped: How to force Sphinx to use Python 3.x interpreter