summaryrefslogtreecommitdiff
path: root/sphinx/domains/python.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r--sphinx/domains/python.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index fae1991c7..64a19fc48 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -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):
@@ -915,8 +926,8 @@ class PyModule(SphinxDirective):
# the platform and synopsis aren't printed; in fact, they are only
# used in the modindex currently
ret.append(target)
- indextext = _('%s (module)') % modname
- inode = addnodes.index(entries=[('single', indextext, node_id, '', None)])
+ indextext = '%s; %s' % (pairindextypes['module'], modname)
+ inode = addnodes.index(entries=[('pair', indextext, node_id, '', None)])
ret.append(inode)
return ret