summaryrefslogtreecommitdiff
path: root/sphinx/ext/inheritance_diagram.py
diff options
context:
space:
mode:
authorMichael Goerz <goerz@stanford.edu>2019-03-10 18:37:05 -0400
committerMichael Goerz <goerz@stanford.edu>2019-03-10 18:37:05 -0400
commit1f136215c18fc75eb9402ec7da083f9022703d71 (patch)
treed09441b44372dcaf7b7899f19202bfa17329f0f2 /sphinx/ext/inheritance_diagram.py
parent332dd5d89f7d5f3135006580c5702bb83843d476 (diff)
downloadsphinx-git-1f136215c18fc75eb9402ec7da083f9022703d71.tar.gz
Fix docs of inheritance-diagram "parts" option
The documentation now correctly describes the behavior of the ``parts`` option in an inheritance-diagram directive: it gives the number of parts that are *kept* not dropped. The option now also accepts negative values, which drops parts from the left (which is the what the documentation incorrectly claimed the option would do for positive values) As a form of testing of the new functionality, the documentation for the inheritance_diagram extension now includes a section "Examples" that demonstrate the different possibilities. This would fail to build without the patch. Closes #4872
Diffstat (limited to 'sphinx/ext/inheritance_diagram.py')
-rw-r--r--sphinx/ext/inheritance_diagram.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py
index cfdac4803..df3ff01ed 100644
--- a/sphinx/ext/inheritance_diagram.py
+++ b/sphinx/ext/inheritance_diagram.py
@@ -167,11 +167,17 @@ class InheritanceGraph:
"""Return name and bases for all classes that are ancestors of
*classes*.
- *parts* gives the number of dotted name parts that is removed from the
- displayed node names.
-
- *top_classes* gives the name(s) of the top most ancestor class to traverse
- to. Multiple names can be specified separated by comma.
+ *parts* gives the number of dotted name parts to include in the
+ displayed node names, from right to left. If given as a negative, the
+ number of parts to drop from the left. A value of 0 displays the full
+ dotted name. E.g. ``sphinx.ext.inheritance_diagram.InheritanceGraph``
+ with ``parts=2`` or ``parts=-2`` gets displayed as
+ ``inheritance_diagram.InheritanceGraph``, and as
+ ``ext.inheritance_diagram.InheritanceGraph`` with ``parts=3`` or
+ ``parts=-1``.
+
+ *top_classes* gives the name(s) of the top most ancestor class to
+ traverse to. Multiple names can be specified separated by comma.
"""
all_classes = {}
py_builtins = vars(builtins).values()
@@ -332,7 +338,7 @@ class InheritanceDiagram(SphinxDirective):
optional_arguments = 0
final_argument_whitespace = True
option_spec = {
- 'parts': directives.nonnegative_int,
+ 'parts': int,
'private-bases': directives.flag,
'caption': directives.unchanged,
'top-classes': directives.unchanged_required,