diff --git a/src/sage/misc/rest_index_of_methods.py b/src/sage/misc/rest_index_of_methods.py index 82b988deda2..17bad8336d8 100644 --- a/src/sage/misc/rest_index_of_methods.py +++ b/src/sage/misc/rest_index_of_methods.py @@ -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. @@ -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 @@ -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)) @@ -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)