mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #7219: py:function directive generates incorrect index entry
This commit is contained in:
parent
7887615374
commit
ce25d0080e
2
CHANGES
2
CHANGES
@ -24,6 +24,8 @@ Bugs fixed
|
||||
argument lists, and more comprehensive error messages in some cases.
|
||||
* C, C++, fix crash and wrong duplicate warnings related to anon symbols.
|
||||
* #6477: Escape first "!" in a cross reference linking no longer possible
|
||||
* #7219: py domain: The index entry generated by ``py:function`` directive is
|
||||
different with one from ``index`` directive with "builtin" type
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -551,12 +551,23 @@ class PyFunction(PyObject):
|
||||
def needs_arglist(self) -> bool:
|
||||
return True
|
||||
|
||||
def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str:
|
||||
def add_target_and_index(self, name_cls: Tuple[str, str], sig: str,
|
||||
signode: desc_signature) -> None:
|
||||
super().add_target_and_index(name_cls, sig, signode)
|
||||
modname = self.options.get('module', self.env.ref_context.get('py:module'))
|
||||
node_id = signode['ids'][0]
|
||||
|
||||
name, cls = name_cls
|
||||
if modname:
|
||||
return _('%s() (in module %s)') % (name, modname)
|
||||
text = _('%s() (in module %s)') % (name, modname)
|
||||
self.indexnode['entries'].append(('single', text, node_id, '', None))
|
||||
else:
|
||||
return _('%s() (built-in function)') % name
|
||||
text = '%s; %s()' % (pairindextypes['builtin'], name)
|
||||
self.indexnode['entries'].append(('pair', text, node_id, '', None))
|
||||
|
||||
def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str:
|
||||
# add index in own add_target_and_index() instead.
|
||||
return None
|
||||
|
||||
|
||||
class PyDecoratorFunction(PyFunction):
|
||||
|
@ -461,6 +461,7 @@ def test_pydata(app):
|
||||
|
||||
def test_pyfunction(app):
|
||||
text = (".. py:function:: func1\n"
|
||||
".. py:module:: example\n"
|
||||
".. py:function:: func2\n"
|
||||
" :async:\n")
|
||||
domain = app.env.get_domain('py')
|
||||
@ -469,15 +470,25 @@ def test_pyfunction(app):
|
||||
[desc, ([desc_signature, ([desc_name, "func1"],
|
||||
[desc_parameterlist, ()])],
|
||||
[desc_content, ()])],
|
||||
nodes.target,
|
||||
addnodes.index,
|
||||
addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_annotation, "async "],
|
||||
[desc_addname, "example."],
|
||||
[desc_name, "func2"],
|
||||
[desc_parameterlist, ()])],
|
||||
[desc_content, ()])]))
|
||||
assert_node(doctree[0], addnodes.index,
|
||||
entries=[('pair', 'built-in function; func1()', 'func1', '', None)])
|
||||
assert_node(doctree[3], addnodes.index,
|
||||
entries=[('single', 'example (module)', 'module-example', '', None)])
|
||||
assert_node(doctree[4], addnodes.index,
|
||||
entries=[('single', 'func2() (in module example)', 'example.func2', '', None)])
|
||||
|
||||
assert 'func1' in domain.objects
|
||||
assert domain.objects['func1'] == ('index', 'func1', 'function')
|
||||
assert 'func2' in domain.objects
|
||||
assert domain.objects['func2'] == ('index', 'func2', 'function')
|
||||
assert 'example.func2' in domain.objects
|
||||
assert domain.objects['example.func2'] == ('index', 'example.func2', 'function')
|
||||
|
||||
|
||||
def test_pymethod_options(app):
|
||||
|
Loading…
Reference in New Issue
Block a user