Skip to content

Commit 90d2653

Browse files
author
Release Manager
committed
gh-40753: Handle aliased functions and methods in generated documentation Closes #40649. I added AUTHORS in `src/sage/misc/sagedoc_conf.py` based on the previous copyright header. From the git history other people have touched this file, but it mostly looked like refactoring/moving code around. If I missed anyone who should be listed in the AUTHORS I'm happy to add them. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. URL: #40753 Reported by: Vincent Macri Reviewer(s): Kwankyu Lee, Tobias Diez, Vincent Macri
2 parents bc7c98a + 36f57f3 commit 90d2653

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/sage/combinat/designs/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5611,4 +5611,4 @@ def ca_41_2_6_6():
56115611
LIST_OF_EDS=LIST_OF_EDS,
56125612
LIST_OF_CA_CONSTRUCTIONS=LIST_OF_CA_CONSTRUCTIONS)
56135613
del LIST_OF_OA_CONSTRUCTIONS, LIST_OF_MOLS_CONSTRUCTIONS, LIST_OF_VMT_VECTORS,LIST_OF_DF, LIST_OF_DM, LIST_OF_QDM, LIST_OF_EDS, LIST_OF_BIBD, LIST_OF_CA_CONSTRUCTIONS
5614-
del PolynomialRing, ZZ, a,
5614+
del PolynomialRing, ZZ, a, f,

src/sage/misc/sagedoc_conf.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
r"""
22
Sphinx configuration shared by sage.misc.sphinxify and sage_docbuild
3+
4+
AUTHORS:
5+
6+
- Matthias Koeppe, Kwankyu Lee (2022): initial version
7+
- Vincent Macri (2025-09-01): process_docstring_aliases
38
"""
49

510
# ****************************************************************************
611
# Copyright (C) 2022 Matthias Koeppe <[email protected]>
12+
# 2022 Kwankyu Lee <[email protected]>
13+
# 2025 Vincent Macri <[email protected]>
714
#
815
# This program is free software: you can redistribute it and/or modify
916
# it under the terms of the GNU General Public License as published by
@@ -24,9 +31,47 @@ def process_docstring_aliases(app, what, name, obj, options, docstringlines):
2431
"""
2532
Change the docstrings for aliases to point to the original object.
2633
"""
27-
basename = name.rpartition('.')[2]
28-
if hasattr(obj, '__name__') and obj.__name__ != basename:
29-
docstringlines[:] = ['See :obj:`%s`.' % name]
34+
35+
if what not in ('function', 'method'):
36+
# Alias detection doesn't make sense for modules.
37+
# Alias handling is implemented for classes in:
38+
# src/sage_docbuild/ext/sage_autodoc.py
39+
40+
# Since sage_autodoc is supposed to be replaced (issue #30893)
41+
# we implement function/method alias handling here rather than
42+
# where class alias handling is implemented.
43+
return
44+
45+
if not hasattr(obj, '__name__'):
46+
# obj has no __name__
47+
# This usually happens with factory functions, which should have their
48+
# own docstring anyway.
49+
return # Skip alias detection if __name__ is not present
50+
51+
obj_name = name.rpartition('.')[2] # Unqualified name
52+
original_name = obj.__name__
53+
54+
if obj_name == original_name or original_name.startswith('_'):
55+
# If obj_name == original_name this is not an alias.
56+
57+
# If original_name starts with '_' then this is a public alias
58+
# of a private function/method and so we keep the docstring.
59+
return None
60+
61+
if what == 'method':
62+
docstringlines[:] = [f'alias of :meth:`{original_name}`.']
63+
return
64+
65+
# We now have `what == 'function'`
66+
67+
if original_name != '<lambda>':
68+
docstringlines[:] = [f'alias of :func:`{original_name}`.']
69+
return
70+
71+
# If original_name == '<lambda>' then the function is
72+
# a lambda expression, hence not an alias of something
73+
# with its own docstring.
74+
return
3075

3176

3277
def process_directives(app, what, name, obj, options, docstringlines):
@@ -164,4 +209,5 @@ def setup(app):
164209
app.connect('autodoc-process-docstring', process_dollars)
165210
app.connect('autodoc-process-docstring', process_inherited)
166211
app.connect('autodoc-process-docstring', skip_TESTS_block)
212+
167213
app.add_transform(SagemathTransform)

src/sage_docbuild/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ def setup(app):
10781078
app.connect('autodoc-process-docstring', process_docstring_module_title)
10791079
app.connect('autodoc-process-docstring', process_dollars)
10801080
app.connect('autodoc-process-docstring', process_inherited)
1081+
app.connect('autodoc-process-docstring', process_docstring_aliases)
10811082
if os.environ.get('SAGE_SKIP_TESTS_BLOCKS', False):
10821083
app.connect('autodoc-process-docstring', skip_TESTS_block)
10831084
app.connect('autodoc-skip-member', skip_member)

0 commit comments

Comments
 (0)