-
Notifications
You must be signed in to change notification settings - Fork 2k
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
autodoc: add :novalue: option #8222
Conversation
4bb9a51
to
f0f291e
Compare
When the :annotation: option is not used, the :novalue: option may be used to remove the value. This is useful when you want to display the type hint but not the value, and you don't want to specify the annotation manually.
f0f291e
to
026a31d
Compare
Add tests for autodata directive options :annotation: and :novalue:.
026a31d
to
877de00
Compare
To clarify, this exists to support Python 3.5 and 2.7 compliant codebases where uninitialized variables cannot exist, but they still want to use type hints with Sphinx autodoc. Support for this case is currently missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now both python 3.5 and 2.7 reached EOL. So I wonder this is still needed.
@@ -326,6 +326,15 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In autodoc, we usually use no-
prefix to disable some feature (ex. no-members
). So it is better to rename this to no-value
(if we adopted this proposal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that imply this PR would require implementing the non-negated version of :value:
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If somebody requests it. But there are no such requests now, AFAIK.
@@ -326,6 +326,15 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:novalue: | |
:no-value: |
.. autodata:: CD_DRIVE | ||
:novalue: | ||
|
||
If both the ``annotation`` and ``novalue`` options are used, ``novalue`` has no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -365,6 +374,9 @@ 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`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:rst:dir:`autodata` and :rst:dir:`autoattribute` now have a ``novalue`` | |
:rst:dir:`autodata` and :rst:dir:`autoattribute` now have a ``no-value`` |
@@ -1598,6 +1598,7 @@ class DataDocumenter(ModuleLevelDocumenter): | |||
priority = -10 | |||
option_spec = dict(ModuleLevelDocumenter.option_spec) | |||
option_spec["annotation"] = annotation_option | |||
option_spec["novalue"] = bool_option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option_spec["novalue"] = bool_option | |
option_spec["no-value"] = bool_option |
@@ -326,6 +326,15 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that imply this PR would require implementing the non-negated version of :value:
as well?
@@ -326,6 +326,15 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If somebody requests it. But there are no such requests now, AFAIK.
@@ -365,6 +374,9 @@ inserting them into the page source under a suitable :rst:dir:`py:module`, | |||
option. | |||
.. versionchanged:: 2.0 | |||
:rst:dir:`autodecorator` added. | |||
.. versionchanged:: 3.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I determined to merge this into 3.4. Please update this.
@@ -11,3 +11,16 @@ | |||
.. autofunction:: target.typehints.incr | |||
|
|||
.. autofunction:: target.typehints.tuple_args | |||
|
|||
.. autodata:: target.typed_vars_py35.attr1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, we don't need to update this file because we have do_autodoc()
helper.
@@ -0,0 +1,11 @@ | |||
#: attr1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
py35
suffix is no longer needed because Sphinx supports py35 or above.
I think no-value
option is not related to "typed variables" at all. So no reason to add new examples. How about using target.integer
instead?
@@ -2024,6 +2025,151 @@ def test_pyclass_for_ClassLevelDocumenter(app): | |||
] | |||
|
|||
|
|||
@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is available since python3.6.') | |||
@pytest.mark.sphinx('html', testroot='ext-autodoc') | |||
def test_pydata_for_DataDeclarationDocumenter(app): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to test with all of data-declaration, py36-style typed attributes and py35-style typed attributes?
Now I posted #8424 as a refined version of this PR. I'd like to merge it instead of this in a few days. Please let me know your opinion :-) |
Subject: Add :novalue: option to display type hint but remove value
Feature or Bugfix
Purpose
When documenting using the
.. autodata::
directive, the :annotation: option only allows displaying nothing or replacing the annotation manually.This adds the :novalue: option which will display the type hint but not the value.
Detail
When the :annotation: option is used, the current behavior is preserved, and :novalue: option does nothing.
When :novalue: is used by itself, the value will not be displayed but any type hint will.
Relates
#8209