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

Classes inheriting from other classes, defined in mocked modules, are ignored #4956

Closed
ederag opened this issue May 10, 2018 · 9 comments
Closed

Comments

@ederag
Copy link
Contributor

ederag commented May 10, 2018

As advised by @djhoese, this is a reopening of #1880.
Unfortunately, this is not #2174 (solved).
Actually, the docstrings of classes inheriting from other classes in mocked modules are ignored.
A real case is described in https://stackoverflow.com/q/50203452/3565696.
Here is a minimal working example, all files in the same directory
(also attached as sphinx-mock-bug.zip, for convenience).

Project module foo.y:

import bar

class FooClass(bar.BarClass):
    """This is myclass"""
    pass

conf.py:

import sys
import os

# The FooClass docstring shows up only if this line is commented out
autodoc_mock_imports = ['bar']

sys.path.insert(0, os.path.abspath('.'))

extensions = [
    'sphinx.ext.autodoc',
]

contents.rst:

foo
===

.. automodule:: foo
    :members:
    :noindex:

And finally, thebar.py "external" module (only used when the autodoc_mock_imports is commented out):

class BarClass():
	pass

The command used to build:
sphinx-build -b html . _build/html

To see the file where the dosctring should be visible:
firefox _build/html/foo.html

Environment info:

  • Linux (openSUSE 42.2)
  • Python version: 3.4.6 and 3.6.4
  • Sphinx version: 1.7.4
    [and same on readthedocs for the real project]
@tk0miya
Copy link
Member

tk0miya commented May 12, 2018

Thank you for reporting. I'll take a look this later.

@tk0miya
Copy link
Member

tk0miya commented May 20, 2018

At present, it can't make subclasses of the class on mocked module.

from sphinx.ext.autodoc.importer import _MockObject

bar = _MockObject()

class FooClass(bar.BarClass):
    """docstring of FooClass"""
    pass


foo = FooClass()
print(foo)          # => <sphinx.ext.autodoc.importer._MockObject object at 0x1101fc828>
print(foo.__doc__)  # => Used by autodoc_mock_imports.

@shimizukawa Do you have any idea for this?

@tk0miya
Copy link
Member

tk0miya commented May 20, 2018

I just made a #4995 . I hope this resolves the issue.
@ederag Could you try this please?

@ederag
Copy link
Contributor Author

ederag commented May 20, 2018

@tk0miya Confirmed, this issue is fixed by #4995. Congratulations !
The geoptics documentation now chokes on signal lines as signal_set_all_selected = pyqtSignal(bool).
It deserves another issue, because commenting out those lines allows the build to complete.

@tk0miya
Copy link
Member

tk0miya commented May 20, 2018

Thank you for confirmation! I'll merge it later (after fixing CI errors).

@ederag
Copy link
Contributor Author

ederag commented May 20, 2018

The pyqtSignal issue is very close to #4931. Comment left there, with a minimal working example.

tk0miya added a commit to tk0miya/sphinx that referenced this issue May 21, 2018
@tk0miya
Copy link
Member

tk0miya commented May 21, 2018

Okay, I'll check it in the thread.

tk0miya added a commit to tk0miya/sphinx that referenced this issue May 21, 2018
tk0miya added a commit that referenced this issue May 21, 2018
Fix #4956: autodoc: Failed to extract document from a subclass of the class on mocked module
@tk0miya
Copy link
Member

tk0miya commented May 21, 2018

Fixed by #4995
Thank you for reporting :-)

@ederag
Copy link
Contributor Author

ederag commented Jun 7, 2018

Now it is possible to document PyQt5 projects on readthedocs, with simple configuration tweaks.
Thanks a lot !

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

2 participants