diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-15 02:22:45 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-15 14:20:30 +0900 |
| commit | 5676fdeb4ede6e2f927c1cd2e05148462455cbcc (patch) | |
| tree | e8b7c8b295bf9cd372ba4161a0eb3f8d15561076 | |
| parent | 6082ce67a4800b796cb0d267725679f7f4ca9f48 (diff) | |
| download | sphinx-git-5676fdeb4ede6e2f927c1cd2e05148462455cbcc.tar.gz | |
Rename :novalue: option to :no-value: option
According to the existing options of autodoc directives, `:novalue:`
option is now renamed to `:no-value:` option.
| -rw-r--r-- | doc/usage/extensions/autodoc.rst | 10 | ||||
| -rw-r--r-- | sphinx/ext/autodoc/__init__.py | 6 | ||||
| -rw-r--r-- | tests/test_ext_autodoc_autoattribute.py | 42 | ||||
| -rw-r--r-- | tests/test_ext_autodoc_autodata.py | 41 |
4 files changed, 91 insertions, 8 deletions
diff --git a/doc/usage/extensions/autodoc.rst b/doc/usage/extensions/autodoc.rst index 1e7bad8df..382d3160c 100644 --- a/doc/usage/extensions/autodoc.rst +++ b/doc/usage/extensions/autodoc.rst @@ -326,13 +326,13 @@ inserting them into the page source under a suitable :rst:dir:`py:module`, By default, without ``annotation`` option, Sphinx tries to obtain the value of the variable and print it after the name. - The ``novalue`` option can be used instead of a blank ``annotation`` to show the + The ``no-value`` option can be used instead of a blank ``annotation`` to show the type hint but not the value:: .. autodata:: CD_DRIVE - :novalue: + :no-value: - If both the ``annotation`` and ``novalue`` options are used, ``novalue`` has no + If both the ``annotation`` and ``no-value`` options are used, ``no-value`` has no effect. For module data members and class attributes, documentation can either be put @@ -374,8 +374,8 @@ inserting them into the page source under a suitable :rst:dir:`py:module`, option. .. versionchanged:: 2.0 :rst:dir:`autodecorator` added. - .. versionchanged:: 3.3 - :rst:dir:`autodata` and :rst:dir:`autoattribute` now have a ``novalue`` + .. versionchanged:: 3.4 + :rst:dir:`autodata` and :rst:dir:`autoattribute` now have a ``no-value`` option. .. note:: diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index c1b3d1afc..d2c0b2b5c 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1690,7 +1690,7 @@ class DataDocumenter(ModuleLevelDocumenter): priority = -10 option_spec = dict(ModuleLevelDocumenter.option_spec) option_spec["annotation"] = annotation_option - option_spec["novalue"] = bool_option + option_spec["no-value"] = bool_option @classmethod def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any @@ -1726,7 +1726,7 @@ class DataDocumenter(ModuleLevelDocumenter): sourcename) try: - if self.object is UNINITIALIZED_ATTR or self.options.novalue: + if self.object is UNINITIALIZED_ATTR or self.options.no_value: pass else: objrepr = object_description(self.object) @@ -2022,7 +2022,7 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter): member_order = 60 option_spec = dict(ModuleLevelDocumenter.option_spec) option_spec["annotation"] = annotation_option - option_spec["novalue"] = bool_option + option_spec["no-value"] = bool_option # must be higher than the MethodDocumenter, else it will recognize # some non-data descriptors as methods diff --git a/tests/test_ext_autodoc_autoattribute.py b/tests/test_ext_autodoc_autoattribute.py new file mode 100644 index 000000000..ea3dd1dfd --- /dev/null +++ b/tests/test_ext_autodoc_autoattribute.py @@ -0,0 +1,42 @@ +""" + test_ext_autodoc_autoattribute + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Test the autodoc extension. This tests mainly the Documenters; the auto + directives are tested in a test source file translated by test_build. + + :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest +from test_ext_autodoc import do_autodoc + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autoattribute(app): + actual = do_autodoc(app, 'attribute', 'target.Class.attr') + assert list(actual) == [ + '', + '.. py:attribute:: Class.attr', + ' :module: target', + " :value: 'bar'", + '', + ' should be documented -- süß', + '', + ] + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autoattribute_novalue(app): + options = {'no-value': True} + actual = do_autodoc(app, 'attribute', 'target.Class.attr', options) + assert list(actual) == [ + '', + '.. py:attribute:: Class.attr', + ' :module: target', + " :value: 'bar'", + '', + ' should be documented -- süß', + '', + ] diff --git a/tests/test_ext_autodoc_autodata.py b/tests/test_ext_autodoc_autodata.py new file mode 100644 index 000000000..7e4471db9 --- /dev/null +++ b/tests/test_ext_autodoc_autodata.py @@ -0,0 +1,41 @@ +""" + test_ext_autodoc_autodata + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Test the autodoc extension. This tests mainly the Documenters; the auto + directives are tested in a test source file translated by test_build. + + :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest +from test_ext_autodoc import do_autodoc + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autodata(app): + actual = do_autodoc(app, 'data', 'target.integer') + assert list(actual) == [ + '', + '.. py:data:: integer', + ' :module: target', + ' :value: 1', + '', + ' documentation for the integer', + '', + ] + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autodata_novalue(app): + options = {'no-value': True} + actual = do_autodoc(app, 'data', 'target.integer', options) + assert list(actual) == [ + '', + '.. py:data:: integer', + ' :module: target', + '', + ' documentation for the integer', + '', + ] |
