Skip to content

Commit

Permalink
fix issue sagemath#36178
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Sep 2, 2023
1 parent 6ea1fe9 commit 1f57583
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/sage/misc/rest_index_of_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sage.misc.sageinspect import is_function_or_cython_function as _isfunction


def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True):
def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True, root=None):
r"""
Return a ReST table describing a list of functions.
Expand Down Expand Up @@ -43,6 +43,10 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True):
will be filtered out. This can be useful to disable for making indexes of
e.g. catalog modules such as :mod:`sage.coding.codes_catalog`.
- ``root`` -- (default: ``None``); the module, or class, whose elements are
to be listed. This is needed to recover the class when this method is
called from :meth:`gen_thematic_rest_table_index`.
.. WARNING::
The ReST tables returned by this function use '@' as a delimiter for
Expand Down Expand Up @@ -169,14 +173,24 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True):
if sort:
list_of_entries.sort(key=fname)

obj_or_root_is_class = False
if inspect.isclass(root):
obj_or_root_is_class = True
class_name = root.__name__
module_name = root.__module__
elif inspect.isclass(obj):
obj_or_root_is_class = True
class_name = obj.__name__
module_name = obj.__module__

for e in list_of_entries:
if inspect.ismethod(e):
link = ":meth:`~{module}.{cls}.{func}`".format(
module=e.im_class.__module__, cls=e.im_class.__name__,
func=fname(e))
elif _isfunction(e) and inspect.isclass(obj):
elif _isfunction(e) and obj_or_root_is_class:
link = ":meth:`~{module}.{cls}.{func}`".format(
module=obj.__module__, cls=obj.__name__, func=fname(e))
module=module_name, cls=class_name, func=fname(e))
elif _isfunction(e):
link = ":func:`~{module}.{func}`".format(
module=e.__module__, func=fname(e))
Expand Down Expand Up @@ -317,7 +331,7 @@ def gen_thematic_rest_table_index(root,additional_categories=None,only_local_fun
except AttributeError:
doc_ind = "Unsorted"
theme_to_function[doc_ind].append(f)
s = ["**"+theme+"**\n\n"+gen_rest_table_index(list_of_functions,names=names)
s = ["**" + theme + "**\n\n" + gen_rest_table_index(list_of_functions, names=names, root=root)
for theme, list_of_functions in sorted(theme_to_function.items())]
return "\n\n".join(s)

Expand Down

0 comments on commit 1f57583

Please sign in to comment.