-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with ABC-derived classes having their members ignored in Py…
…thon 3 ABC-derived classes (i.e. those deriving from the `abc` and `collections.abc` modules) now include their members (as defined in `__dict__`) in generated `autosummary` RST. `__slots__` may still be used to override `__dict__`, but if an ABC-derived class has empty slots, its `__dict__` will be used instead. This was only an issue in Python 3 when ``:inherited-members:`` was not in effect. Fixes #52
- Loading branch information
1 parent
d46a0c1
commit 1f4d426
Showing
9 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This example is to make sure that classes derived from the `abc` module will | ||
have their members listed when ``:inherited-members:`` is not in effect | ||
(https://github.com/astropy/sphinx-automodapi/issues/52). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. automodapi:: sphinx_automodapi.tests.example_module.abstract_classes |
27 changes: 27 additions & 0 deletions
27
...pi/sphinx_automodapi.tests.example_module.abstract_classes.SequenceSubclass.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
SequenceSubclass | ||
================ | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
.. autoclass:: SequenceSubclass | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~SequenceSubclass.my_property | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~SequenceSubclass.my_method | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoattribute:: my_property | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: my_method |
19 changes: 19 additions & 0 deletions
19
sphinx_automodapi/tests/cases/abstract_classes/output/index.rst.automodapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
sphinx_automodapi.tests.example_module.abstract_classes Module | ||
-------------------------------------------------------------- | ||
|
||
.. automodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
Classes | ||
^^^^^^^ | ||
|
||
.. automodsumm:: sphinx_automodapi.tests.example_module.abstract_classes | ||
:classes-only: | ||
:toctree: api | ||
|
||
Class Inheritance Diagram | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automod-diagram:: sphinx_automodapi.tests.example_module.abstract_classes | ||
:private-bases: | ||
:parts: 1 |
6 changes: 6 additions & 0 deletions
6
sphinx_automodapi/tests/cases/abstract_classes/output/index.rst.automodsumm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. currentmodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
SequenceSubclass |
43 changes: 43 additions & 0 deletions
43
sphinx_automodapi/tests/example_module/abstract_classes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
try: | ||
# Python 3 | ||
from collections.abc import Sequence | ||
except ImportError: | ||
# Python 2 (this import also works in Python <= 3.7, but will be removed in | ||
# Python 3.8) | ||
from collections import Sequence | ||
|
||
__all__ = ['SequenceSubclass'] | ||
|
||
|
||
class SequenceSubclass(Sequence): | ||
""" | ||
Inherits from an ABC. | ||
""" | ||
|
||
def __init__(self): | ||
self._items = [] | ||
|
||
def __len__(self): | ||
""" | ||
Must be defined for the collections.abc.Sequence base class. | ||
""" | ||
return len(self._items) | ||
|
||
def __getitem__(self, key): | ||
""" | ||
Must be defined for the collections.abc.Sequence base class. | ||
""" | ||
return self._items[key] | ||
|
||
def my_method(self, parameter): | ||
""" | ||
An example method. | ||
""" | ||
pass | ||
|
||
@property | ||
def my_property(self): | ||
""" | ||
An example property. | ||
""" | ||
return 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters