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

Napoleon extension gives unexpected error message when processing the docstring of a function written in Cython #8097

Closed
tovrstra opened this issue Aug 10, 2020 · 2 comments

Comments

@tovrstra
Copy link

Describe the bug
Our CI crashed with a rather cryptic error message when building the documentation, see https://travis-ci.com/github/theochem/iodata/jobs/370345521#L1842

Manual checks revealed this was related to the Napolean extension. (Commenting out napoleon from conf.py prevents the error message, but this is not a helpful solution.)

By adding a line print(obj) to the function _process_docstring in the file sphinx/ext/napoleon/__init__.py, the Cython extension appears to be the cause. The error message with the extra print lines then becomes:

Extension error:
Handler <function _process_docstring at 0x7f1a9f310cb0> for event 'autodoc-process-docstring' threw an exception (exception: module, class, method, function, traceback, frame, or code object was expected, got builtin_function_or_method)
<module 'iodata.overlap_accel' from '/home/toon/univ/code/iodata/iodata/overlap_accel.cpython-37m-x86_64-linux-gnu.so'>
<built-in function add_overlap>
<built-in function fac2>
make: *** [Makefile:21: html] Error 2

To Reproduce
Steps to reproduce the behavior:

git clone git@github.com:theochem/iodata.git
cd iodata
./setup.py build_ext -i
cd doc
make html

Expected behavior
A more understandable error message would be helpful. Ideally, Napoleon should just process docstrings of "builtin" functions. These are not necessarily built-in to Python. They can be functions from any extension module.

Your project
https://github.com/theochem/iodata/

Screenshots
not applicable

Environment info

  • OS: Fedora 32
  • Python version: 3.7.7
  • Sphinx version: 3.2.0
  • Sphinx extensions: sphinx.ext.napoleon
  • Extra tools: none

Additional context
not applicable

@keewis
Copy link
Contributor

keewis commented Aug 11, 2020

I think this is a duplicate of #8074 and fixed in #8077. The reason is that inspect.getfile, which is used to provide a location for a warning, raises a TypeError for docstrings defined in C extensions (which I completely missed when writing #7690). The fix will be included in 3.2.1

@tovrstra
Copy link
Author

@keewis. Thanks for explaining. It looks very similar indeed. I just tested with the 3.2.x development branch and the error disappears indeed.

@tk0miya tk0miya added this to the 3.2.1 milestone Aug 12, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 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