Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Bugs fixed
does not match the language name, such as Chinese (which reuses the
English stemmer) and Dutch (which uses the Dutch Porter stemmer).
Patch by Hugo van Kemenade
* #11242: Avoid adding redundant parentheses to cross-reference titles that
already end with a parenthesized argument list.
Patch by Jared Dillard.


Release 9.1.0 (released Dec 31, 2025)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
def update_title_and_target(self, title: str, target: str) -> tuple[str, str]:
if not self.has_explicit_title:
if self.config.add_function_parentheses:
if not title.endswith('()'):
if not title.endswith(')'):
# add parentheses to the title
title += '()'
else:
Expand Down
30 changes: 19 additions & 11 deletions tests/test_markup/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,25 @@ def test_XRefRole(app: SphinxTestApp) -> None:

# fix_parens
role = XRefRole(fix_parens=True)
doctrees, errors = role('ref', 'rawtext', 'text()', 5, inliner, {}, []) # type: ignore[arg-type]
assert_node(doctrees[0], [addnodes.pending_xref, nodes.literal, 'text()'])
assert_node(
doctrees[0],
refdoc='dummy',
refdomain='',
reftype='ref',
reftarget='text',
refexplicit=False,
refwarn=False,
)
for text, title, target in (
('text', 'text()', 'text'),
('text()', 'text()', 'text'),
('text(arg)', 'text(arg)', 'text(arg)'),
):
doctrees, errors = role( # type: ignore[arg-type]
'ref', 'rawtext', text, 5, inliner, {}, []
)
assert_node(doctrees[0], [addnodes.pending_xref, nodes.literal, title])
assert_node(
doctrees[0],
refdoc='dummy',
refdomain='',
reftype='ref',
reftarget=target,
refexplicit=False,
refwarn=False,
)
assert errors == []

# lowercase
role = XRefRole(lowercase=True)
Expand Down
Loading