-
-
Notifications
You must be signed in to change notification settings - Fork 659
Handle aliased functions and methods in generated documentation #40753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
r""" | ||
Sphinx configuration shared by sage.misc.sphinxify and sage_docbuild | ||
|
||
AUTHORS: | ||
|
||
- Matthias Koeppe, Kwankyu Lee (2022): initial version | ||
- Vincent Macri (2025-09-01): process_docstring_aliases | ||
""" | ||
|
||
# **************************************************************************** | ||
# Copyright (C) 2022 Matthias Koeppe <[email protected]> | ||
# 2022 Kwankyu Lee <[email protected]> | ||
# 2025 Vincent Macri <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# 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): | |
""" | ||
Change the docstrings for aliases to point to the original object. | ||
""" | ||
basename = name.rpartition('.')[2] | ||
if hasattr(obj, '__name__') and obj.__name__ != basename: | ||
docstringlines[:] = ['See :obj:`%s`.' % name] | ||
|
||
if what not in ('function', 'method'): | ||
# Alias detection doesn't make sense for modules. | ||
# Alias handling is implemented for classes in: | ||
# src/sage_docbuild/ext/sage_autodoc.py | ||
|
||
# Since sage_autodoc is supposed to be replaced (issue #30893) | ||
# we implement function/method alias handling here rather than | ||
# where class alias handling is implemented. | ||
return | ||
|
||
if not hasattr(obj, '__name__'): | ||
# obj has no __name__ | ||
# This usually happens with factory functions, which should have their | ||
# own docstring anyway. | ||
return # Skip alias detection if __name__ is not present | ||
|
||
obj_name = name.rpartition('.')[2] # Unqualified name | ||
original_name = obj.__name__ | ||
|
||
if obj_name == original_name or original_name.startswith('_'): | ||
# If obj_name == original_name this is not an alias. | ||
|
||
# If original_name starts with '_' then this is a public alias | ||
# of a private function/method and so we keep the docstring. | ||
return None | ||
|
||
if what == 'method': | ||
docstringlines[:] = [f'alias of :meth:`{original_name}`.'] | ||
return | ||
|
||
# We now have `what == 'function'` | ||
|
||
if original_name != '<lambda>': | ||
docstringlines[:] = [f'alias of :func:`{original_name}`.'] | ||
return | ||
|
||
# If original_name == '<lambda>' then the function is | ||
# a lambda expression, hence not an alias of something | ||
# with its own docstring. | ||
return | ||
|
||
|
||
def process_directives(app, what, name, obj, options, docstringlines): | ||
|
@@ -164,4 +209,5 @@ def setup(app): | |
app.connect('autodoc-process-docstring', process_dollars) | ||
app.connect('autodoc-process-docstring', process_inherited) | ||
app.connect('autodoc-process-docstring', skip_TESTS_block) | ||
|
||
app.add_transform(SagemathTransform) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.