Skip to content

Commit 14698b7

Browse files
committed
Add tilde modifier support for :py:deco: role
1 parent c76d1bd commit 14698b7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Features added
2020
``linkcheck_allowed_redirects = {}``.
2121
Patch by Adam Turner.
2222
* #13497: Support C domain objects in the table of contents.
23+
* #13528: Add tilde modifier support for :rst:role:`:py:deco:`
24+
Patch by Shengyu Zhang.
2325

2426
Bugs fixed
2527
----------

sphinx/domains/python/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,24 @@ def __init__(
603603
warn_dangling: bool = False,
604604
) -> None:
605605
super().__init__(
606-
fix_parens=True,
606+
fix_parens=fix_parens,
607607
lowercase=lowercase,
608608
nodeclass=nodeclass,
609609
innernodeclass=innernodeclass,
610610
warn_dangling=warn_dangling,
611611
)
612612

613-
def update_title_and_target(self, title: str, target: str) -> tuple[str, str]:
613+
def process_link(
614+
self,
615+
env: BuildEnvironment,
616+
refnode: Element,
617+
has_explicit_title: bool,
618+
title: str,
619+
target: str,
620+
) -> tuple[str, str]:
621+
title, target = super().process_link(
622+
env, refnode, has_explicit_title, title, target
623+
)
614624
return f'@{title}', target
615625

616626

tests/test_domains/test_domain_py.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,3 +1791,21 @@ def test_pep_695_and_pep_696_whitespaces_in_default(app, tp_list, tptext):
17911791
text = f'.. py:function:: f{tp_list}() -> Annotated[T, Qux[int]()]'
17921792
doctree = restructuredtext.parse(app, text)
17931793
assert doctree.astext() == f'\n\nf{tptext}() -> Annotated[T, Qux[int]()]\n\n'
1794+
1795+
1796+
def test_deco_role(app):
1797+
text = """:py:deco:`foo.bar`
1798+
.. py:decorator:: foo.bar
1799+
:no-contents-entry:
1800+
:no-index-entry:
1801+
:no-typesetting:"""
1802+
doctree = restructuredtext.parse(app, text)
1803+
assert doctree.astext() == f'@bar\n\n\n\n'
1804+
1805+
text = """:py:deco:`~foo.bar`
1806+
.. py:decorator:: foo.bar
1807+
:no-contents-entry:
1808+
:no-index-entry:
1809+
:no-typesetting:"""
1810+
doctree = restructuredtext.parse(app, text)
1811+
assert doctree.astext() == f'@bar\n\n\n\n'

0 commit comments

Comments
 (0)