Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No docs generated for functools.partial functions #5211

Closed
ioanna-i opened this issue Jul 24, 2018 · 4 comments
Closed

No docs generated for functools.partial functions #5211

ioanna-i opened this issue Jul 24, 2018 · 4 comments

Comments

@ioanna-i
Copy link

Subject: No docs appear for functions created via functools.partial

Problem

I have a module which includes some functions created using functools.partial and I would like to include those in my doc page. I've used func.__doc__ = ... to set the docstring for each partial function.
When I generate the docs the partial functions are completely ignored. I've created a toy example below to reproduce the problem.

Procedure to reproduce the problem

I created a directory with this structure:

- doc/
- example/__init__.py  #empty
- example/code.py

example/code.py contains:

from functools import partial

def my_func(a, b, c):
    """my_func docstring

    Args:
        a (int): a
        b (int): b
        c (int): c

    Returns:
        int: a + b + c
    """
    return a + b + c

partial_func = partial(my_func, c=10)
partial_func.__doc__ = """partial_func docstring
    Args:
        a (int): a
        b (int): b

    Returns:
        int: a + b + 10
"""

I set up my python environment and sphinx using conda like this:

$ conda create -n test python=3
$ conda activate test
$ conda install sphinx
$ cd doc
$ sphinx-quickstart
> Separate source and build directories (y/n) [n]: y
> Name prefix for templates and static dir [_]: 
> Project name: Example
> Author name(s): Ioanna
> Project release []: 
> Project language [en]: 
> Source file suffix [.rst]: 
> Name of your master document (without suffix) [index]: 
> Do you want to use the epub builder (y/n) [n]: 
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: 
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: 
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: 
> coverage: checks for documentation coverage (y/n) [n]: 
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]: 
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: 
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: 
> viewcode: include links to the source code of documented Python objects (y/n) [n]: 
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: 
> Create Makefile? (y/n) [y]: 
> Create Windows command file? (y/n) [y]: n

I also modified the resulting conf.py to add 'sphinx.ext.napoleon' to the extensions being used to make sure it recognizes the Google style docstrings.

Then I added this to index.rst:

.. automodule:: example.code
    :members:

Error logs / results

Running make html gives the following output

Running Sphinx v1.7.5
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] index                                                                                                         
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                          
generating indices... genindex py-modindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded.

The HTML pages are in build/html.

The resulting docs correctly display the docs for my_func, but partial_func is completely absent. It doesn't even appear as a function signature.

I tried setting :members: partial_func in index.rst as well, but it still didn't appear.

Environment info

  • OS: Fedora 25
  • Python version: 3.7.0
  • Sphinx version: 1.7.5
  • Here's the output of conda list on my test env:
alabaster                 0.7.11                   py37_0  
asn1crypto                0.24.0                   py37_0  
babel                     2.6.0                    py37_0  
ca-certificates           2018.03.07                    0  
certifi                   2018.4.16                py37_0  
cffi                      1.11.5           py37h9745a5d_0  
chardet                   3.0.4                    py37_1  
cryptography              2.2.2            py37h14c3975_0  
docutils                  0.14                     py37_0  
idna                      2.7                      py37_0  
imagesize                 1.0.0                    py37_0  
jinja2                    2.10                     py37_0  
libedit                   3.1.20170329         h6b74fdf_2  
libffi                    3.2.1                hd88cf55_4  
libgcc-ng                 7.2.0                hdf63c60_3  
libstdcxx-ng              7.2.0                hdf63c60_3  
markupsafe                1.0              py37h14c3975_1  
ncurses                   6.1                  hf484d3e_0  
openssl                   1.0.2o               h20670df_0  
packaging                 17.1                     py37_0  
pip                       10.0.1                   py37_0  
pycparser                 2.18                     py37_1  
pygments                  2.2.0                    py37_0  
pyopenssl                 18.0.0                   py37_0  
pyparsing                 2.2.0                    py37_1  
pysocks                   1.6.8                    py37_0  
python                    3.7.0                hc3d631a_0  
pytz                      2018.5                   py37_0  
readline                  7.0                  ha6073c6_4  
requests                  2.19.1                   py37_0  
setuptools                39.2.0                   py37_0  
six                       1.11.0                   py37_1  
snowballstemmer           1.2.1                    py37_0  
sphinx                    1.7.5                    py37_0  
sphinxcontrib             1.0                      py37_1  
sphinxcontrib-websupport  1.1.0                    py37_1  
sqlite                    3.24.0               h84994c4_0  
tk                        8.6.7                hc745277_3  
urllib3                   1.23                     py37_0  
wheel                     0.31.1                   py37_0  
xz                        5.2.4                h14c3975_4  
zlib                      1.2.11               ha838bed_2  
@tk0miya
Copy link
Member

tk0miya commented Jul 24, 2018

inspect.isfunction() considers a partial'ed function is not a function.

>>> import functools
>>> import inspect
>>> def func(x, y): pass
...
>>> func2 = functools.partial(func, 1, 2)
>>>
>>> inspect.isfunction(func)
True
>>> inspect.isfunction(func2)
False

For the reason, autodoc can't matching Documenter class for it. We have to fix its comparison rule.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 15, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 15, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 15, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 16, 2018
tk0miya added a commit to tk0miya/sphinx that referenced this issue Aug 16, 2018
tk0miya added a commit that referenced this issue Aug 16, 2018
Fix #5211: autodoc: No docs generated for functools.partial functions
@tk0miya
Copy link
Member

tk0miya commented Aug 16, 2018

Fixed by #5305.
Thank you for reporting.

@tk0miya tk0miya closed this as completed Aug 16, 2018
@natedileas
Copy link

Will this be fixed in 1.8? Still see the failure on windows, sphinx 1.8.1.

@tk0miya
Copy link
Member

tk0miya commented Sep 29, 2018

@natedileas
I think this was fixed. If you're still in trouble, please file a new issue. I have to investigate that again.
Thanks,

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants