mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #10181: napoleon_use_ivar adds unexpected prefix to vars
Since 4.0, :ivar: items has not been rendered as hyperlinks. So any modules, classes and tilda are now harmful. This removes the prefixing filter for napoleon_use_ivar option. refs: #5129 and #5977
This commit is contained in:
parent
a32d609061
commit
8224f6f44a
4
CHANGES
4
CHANGES
@ -10,6 +10,8 @@ Incompatible changes
|
|||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* ``sphinx.ext.napoleon.docstring.GoogleDocstring._qualify_name()``
|
||||||
|
|
||||||
Features added
|
Features added
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@ -28,6 +30,8 @@ Bugs fixed
|
|||||||
``no-value`` option
|
``no-value`` option
|
||||||
* #9529: LaTeX: named auto numbered footnote (ex. ``[#named]``) that is referred
|
* #9529: LaTeX: named auto numbered footnote (ex. ``[#named]``) that is referred
|
||||||
multiple times was rendered to a question mark
|
multiple times was rendered to a question mark
|
||||||
|
* #10181: napoleon: attributes are displayed like class attributes for google
|
||||||
|
style docstrings when :confval:`napoleon_use_ivar` is enabled
|
||||||
* #10122: sphinx-build: make.bat does not check the installation of sphinx-build
|
* #10122: sphinx-build: make.bat does not check the installation of sphinx-build
|
||||||
command before showing help
|
command before showing help
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- (will be) Removed
|
- (will be) Removed
|
||||||
- Alternatives
|
- Alternatives
|
||||||
|
|
||||||
|
* - ``sphinx.ext.napoleon.docstring.GoogleDocstring._qualify_name()``
|
||||||
|
- 4.5
|
||||||
|
- 6.0
|
||||||
|
- N/A
|
||||||
|
|
||||||
* - ``sphinx.ext.autodoc.AttributeDocumenter._datadescriptor``
|
* - ``sphinx.ext.autodoc.AttributeDocumenter._datadescriptor``
|
||||||
- 4.3
|
- 4.3
|
||||||
- 6.0
|
- 6.0
|
||||||
|
@ -13,11 +13,13 @@
|
|||||||
import collections
|
import collections
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
|
import warnings
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any, Callable, Dict, List, Tuple, Type, Union
|
from typing import Any, Callable, Dict, List, Tuple, Type, Union
|
||||||
|
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.config import Config as SphinxConfig
|
from sphinx.config import Config as SphinxConfig
|
||||||
|
from sphinx.deprecation import RemovedInSphinx60Warning
|
||||||
from sphinx.ext.napoleon.iterators import modify_iter
|
from sphinx.ext.napoleon.iterators import modify_iter
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
@ -631,7 +633,6 @@ class GoogleDocstring:
|
|||||||
if not _type:
|
if not _type:
|
||||||
_type = self._lookup_annotation(_name)
|
_type = self._lookup_annotation(_name)
|
||||||
if self._config.napoleon_use_ivar:
|
if self._config.napoleon_use_ivar:
|
||||||
_name = self._qualify_name(_name, self._obj)
|
|
||||||
field = ':ivar %s: ' % _name
|
field = ':ivar %s: ' % _name
|
||||||
lines.extend(self._format_block(field, _desc))
|
lines.extend(self._format_block(field, _desc))
|
||||||
if _type:
|
if _type:
|
||||||
@ -825,6 +826,8 @@ class GoogleDocstring:
|
|||||||
"".join(after_colon).strip())
|
"".join(after_colon).strip())
|
||||||
|
|
||||||
def _qualify_name(self, attr_name: str, klass: Type) -> str:
|
def _qualify_name(self, attr_name: str, klass: Type) -> str:
|
||||||
|
warnings.warn('%s._qualify_name() is deprecated.' %
|
||||||
|
self.__class__.__name__, RemovedInSphinx60Warning)
|
||||||
if klass and '.' not in attr_name:
|
if klass and '.' not in attr_name:
|
||||||
if attr_name.startswith('~'):
|
if attr_name.startswith('~'):
|
||||||
attr_name = attr_name[1:]
|
attr_name = attr_name[1:]
|
||||||
|
@ -482,6 +482,22 @@ Attributes:
|
|||||||
super-dooper attribute
|
super-dooper attribute
|
||||||
|
|
||||||
:type: numpy.ndarray
|
:type: numpy.ndarray
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_attributes_with_use_ivar(self):
|
||||||
|
docstring = """\
|
||||||
|
Attributes:
|
||||||
|
foo (int): blah blah
|
||||||
|
bar (str): blah blah
|
||||||
|
"""
|
||||||
|
|
||||||
|
config = Config(napoleon_use_ivar=True)
|
||||||
|
actual = str(GoogleDocstring(docstring, config, obj=self.__class__))
|
||||||
|
expected = """\
|
||||||
|
:ivar foo: blah blah
|
||||||
|
:vartype foo: int
|
||||||
|
:ivar bar: blah blah
|
||||||
|
:vartype bar: str
|
||||||
"""
|
"""
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user