Skip to content

Commit bebd6bd

Browse files
authored
Merge pull request sphinx-doc#9633 from tk0miya/9630_autosummary_primary_domain
Fix sphinx-doc#9630: autosummary: Failed to build summary table if primary_domain is not 'py'
2 parents ba2439a + bc01207 commit bebd6bd

File tree

8 files changed

+130
-119
lines changed

8 files changed

+130
-119
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Features added
1616
Bugs fixed
1717
----------
1818

19+
* #9630: autodoc: Failed to build cross references if :confval:`primary_domain`
20+
is not 'py'
21+
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
22+
is not 'py'
23+
1924
Testing
2025
--------
2126

sphinx/ext/autosummary/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ def append_row(*column_texts: str) -> None:
444444
for name, sig, summary, real_name in items:
445445
qualifier = 'obj'
446446
if 'nosignatures' not in self.options:
447-
col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig))
447+
col1 = ':py:%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig))
448448
else:
449-
col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
449+
col1 = ':py:%s:`%s <%s>`' % (qualifier, name, real_name)
450450
col2 = summary
451451
append_row(col1, col2)
452452

sphinx/util/typing.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ def restify(cls: Optional[Type]) -> str:
110110

111111
try:
112112
if cls is None or cls is NoneType:
113-
return ':obj:`None`'
113+
return ':py:obj:`None`'
114114
elif cls is Ellipsis:
115115
return '...'
116116
elif cls in INVALID_BUILTIN_CLASSES:
117-
return ':class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
117+
return ':py:class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
118118
elif inspect.isNewType(cls):
119119
if sys.version_info > (3, 10):
120120
# newtypes have correct module info since Python 3.10+
121121
print(cls, type(cls), dir(cls))
122-
return ':class:`%s.%s`' % (cls.__module__, cls.__name__)
122+
return ':py:class:`%s.%s`' % (cls.__module__, cls.__name__)
123123
else:
124-
return ':class:`%s`' % cls.__name__
124+
return ':py:class:`%s`' % cls.__name__
125125
elif UnionType and isinstance(cls, UnionType):
126126
if len(cls.__args__) > 1 and None in cls.__args__:
127127
args = ' | '.join(restify(a) for a in cls.__args__ if a)
@@ -130,12 +130,12 @@ def restify(cls: Optional[Type]) -> str:
130130
return ' | '.join(restify(a) for a in cls.__args__)
131131
elif cls.__module__ in ('__builtin__', 'builtins'):
132132
if hasattr(cls, '__args__'):
133-
return ':class:`%s`\\ [%s]' % (
133+
return ':py:class:`%s`\\ [%s]' % (
134134
cls.__name__,
135135
', '.join(restify(arg) for arg in cls.__args__),
136136
)
137137
else:
138-
return ':class:`%s`' % cls.__name__
138+
return ':py:class:`%s`' % cls.__name__
139139
else:
140140
if sys.version_info >= (3, 7): # py37+
141141
return _restify_py37(cls)
@@ -155,20 +155,20 @@ def _restify_py37(cls: Optional[Type]) -> str:
155155
if len(cls.__args__) > 1 and cls.__args__[-1] is NoneType:
156156
if len(cls.__args__) > 2:
157157
args = ', '.join(restify(a) for a in cls.__args__[:-1])
158-
return ':obj:`~typing.Optional`\\ [:obj:`~typing.Union`\\ [%s]]' % args
158+
return ':py:obj:`~typing.Optional`\\ [:obj:`~typing.Union`\\ [%s]]' % args
159159
else:
160-
return ':obj:`~typing.Optional`\\ [%s]' % restify(cls.__args__[0])
160+
return ':py:obj:`~typing.Optional`\\ [%s]' % restify(cls.__args__[0])
161161
else:
162162
args = ', '.join(restify(a) for a in cls.__args__)
163-
return ':obj:`~typing.Union`\\ [%s]' % args
163+
return ':py:obj:`~typing.Union`\\ [%s]' % args
164164
elif inspect.isgenericalias(cls):
165165
if isinstance(cls.__origin__, typing._SpecialForm):
166166
text = restify(cls.__origin__) # type: ignore
167167
elif getattr(cls, '_name', None):
168168
if cls.__module__ == 'typing':
169-
text = ':class:`~%s.%s`' % (cls.__module__, cls._name)
169+
text = ':py:class:`~%s.%s`' % (cls.__module__, cls._name)
170170
else:
171-
text = ':class:`%s.%s`' % (cls.__module__, cls._name)
171+
text = ':py:class:`%s.%s`' % (cls.__module__, cls._name)
172172
else:
173173
text = restify(cls.__origin__)
174174

@@ -188,20 +188,20 @@ def _restify_py37(cls: Optional[Type]) -> str:
188188

189189
return text
190190
elif isinstance(cls, typing._SpecialForm):
191-
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
191+
return ':py:obj:`~%s.%s`' % (cls.__module__, cls._name)
192192
elif hasattr(cls, '__qualname__'):
193193
if cls.__module__ == 'typing':
194-
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
194+
return ':py:class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
195195
else:
196-
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
196+
return ':py:class:`%s.%s`' % (cls.__module__, cls.__qualname__)
197197
elif isinstance(cls, ForwardRef):
198-
return ':class:`%s`' % cls.__forward_arg__
198+
return ':py:class:`%s`' % cls.__forward_arg__
199199
else:
200200
# not a class (ex. TypeVar)
201201
if cls.__module__ == 'typing':
202-
return ':obj:`~%s.%s`' % (cls.__module__, cls.__name__)
202+
return ':py:obj:`~%s.%s`' % (cls.__module__, cls.__name__)
203203
else:
204-
return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)
204+
return ':py:obj:`%s.%s`' % (cls.__module__, cls.__name__)
205205

206206

207207
def _restify_py36(cls: Optional[Type]) -> str:
@@ -225,9 +225,9 @@ def _restify_py36(cls: Optional[Type]) -> str:
225225
if (isinstance(cls, typing.TupleMeta) and # type: ignore
226226
not hasattr(cls, '__tuple_params__')):
227227
if module == 'typing':
228-
reftext = ':class:`~typing.%s`' % qualname
228+
reftext = ':py:class:`~typing.%s`' % qualname
229229
else:
230-
reftext = ':class:`%s`' % qualname
230+
reftext = ':py:class:`%s`' % qualname
231231

232232
params = cls.__args__
233233
if params:
@@ -237,9 +237,9 @@ def _restify_py36(cls: Optional[Type]) -> str:
237237
return reftext
238238
elif isinstance(cls, typing.GenericMeta):
239239
if module == 'typing':
240-
reftext = ':class:`~typing.%s`' % qualname
240+
reftext = ':py:class:`~typing.%s`' % qualname
241241
else:
242-
reftext = ':class:`%s`' % qualname
242+
reftext = ':py:class:`%s`' % qualname
243243

244244
if cls.__args__ is None or len(cls.__args__) <= 2:
245245
params = cls.__args__
@@ -262,38 +262,38 @@ def _restify_py36(cls: Optional[Type]) -> str:
262262
if len(params) > 1 and params[-1] is NoneType:
263263
if len(params) > 2:
264264
param_str = ", ".join(restify(p) for p in params[:-1])
265-
return (':obj:`~typing.Optional`\\ '
266-
'[:obj:`~typing.Union`\\ [%s]]' % param_str)
265+
return (':py:obj:`~typing.Optional`\\ '
266+
'[:py:obj:`~typing.Union`\\ [%s]]' % param_str)
267267
else:
268-
return ':obj:`~typing.Optional`\\ [%s]' % restify(params[0])
268+
return ':py:obj:`~typing.Optional`\\ [%s]' % restify(params[0])
269269
else:
270270
param_str = ', '.join(restify(p) for p in params)
271-
return ':obj:`~typing.Union`\\ [%s]' % param_str
271+
return ':py:obj:`~typing.Union`\\ [%s]' % param_str
272272
else:
273-
return ':obj:`Union`'
273+
return ':py:obj:`Union`'
274274
elif hasattr(cls, '__qualname__'):
275275
if cls.__module__ == 'typing':
276-
return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
276+
return ':py:class:`~%s.%s`' % (cls.__module__, cls.__qualname__)
277277
else:
278-
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
278+
return ':py:class:`%s.%s`' % (cls.__module__, cls.__qualname__)
279279
elif hasattr(cls, '_name'):
280280
# SpecialForm
281281
if cls.__module__ == 'typing':
282-
return ':obj:`~%s.%s`' % (cls.__module__, cls._name)
282+
return ':py:obj:`~%s.%s`' % (cls.__module__, cls._name)
283283
else:
284-
return ':obj:`%s.%s`' % (cls.__module__, cls._name)
284+
return ':py:obj:`%s.%s`' % (cls.__module__, cls._name)
285285
elif hasattr(cls, '__name__'):
286286
# not a class (ex. TypeVar)
287287
if cls.__module__ == 'typing':
288-
return ':obj:`~%s.%s`' % (cls.__module__, cls.__name__)
288+
return ':py:obj:`~%s.%s`' % (cls.__module__, cls.__name__)
289289
else:
290-
return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)
290+
return ':py:obj:`%s.%s`' % (cls.__module__, cls.__name__)
291291
else:
292292
# others (ex. Any)
293293
if cls.__module__ == 'typing':
294-
return ':obj:`~%s.%s`' % (cls.__module__, qualname)
294+
return ':py:obj:`~%s.%s`' % (cls.__module__, qualname)
295295
else:
296-
return ':obj:`%s.%s`' % (cls.__module__, qualname)
296+
return ':py:obj:`%s.%s`' % (cls.__module__, qualname)
297297

298298

299299
def stringify(annotation: Any) -> str:

tests/test_ext_autodoc.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ def test_autodoc_inner_class(app):
984984
' .. py:attribute:: Outer.factory',
985985
' :module: target',
986986
'',
987-
' alias of :class:`dict`'
987+
' alias of :py:class:`dict`'
988988
]
989989

990990
actual = do_autodoc(app, 'class', 'target.Outer.Inner', options)
@@ -1009,7 +1009,7 @@ def test_autodoc_inner_class(app):
10091009
'',
10101010
'.. py:class:: InnerChild()',
10111011
' :module: target', '',
1012-
' Bases: :class:`target.Outer.Inner`',
1012+
' Bases: :py:class:`target.Outer.Inner`',
10131013
'',
10141014
' InnerChild docstring',
10151015
'',
@@ -1750,7 +1750,7 @@ def test_autodoc_typed_instance_variables(app):
17501750
'.. py:attribute:: Alias',
17511751
' :module: target.typed_vars',
17521752
'',
1753-
' alias of :class:`target.typed_vars.Derived`',
1753+
' alias of :py:class:`target.typed_vars.Derived`',
17541754
'',
17551755
'.. py:class:: Class()',
17561756
' :module: target.typed_vars',
@@ -1915,12 +1915,12 @@ def test_autodoc_GenericAlias(app):
19151915
' .. py:attribute:: Class.T',
19161916
' :module: target.genericalias',
19171917
'',
1918-
' alias of :class:`~typing.List`\\ [:class:`int`]',
1918+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
19191919
'',
19201920
'.. py:attribute:: T',
19211921
' :module: target.genericalias',
19221922
'',
1923-
' alias of :class:`~typing.List`\\ [:class:`int`]',
1923+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
19241924
]
19251925
else:
19261926
assert list(actual) == [
@@ -1937,15 +1937,15 @@ def test_autodoc_GenericAlias(app):
19371937
'',
19381938
' A list of int',
19391939
'',
1940-
' alias of :class:`~typing.List`\\ [:class:`int`]',
1940+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
19411941
'',
19421942
'',
19431943
'.. py:data:: T',
19441944
' :module: target.genericalias',
19451945
'',
19461946
' A list of int',
19471947
'',
1948-
' alias of :class:`~typing.List`\\ [:class:`int`]',
1948+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
19491949
'',
19501950
]
19511951

@@ -1977,7 +1977,7 @@ def test_autodoc_TypeVar(app):
19771977
'',
19781978
' T6',
19791979
'',
1980-
' alias of :class:`int`',
1980+
' alias of :py:class:`int`',
19811981
'',
19821982
'',
19831983
'.. py:data:: T1',
@@ -2017,15 +2017,15 @@ def test_autodoc_TypeVar(app):
20172017
'',
20182018
' T6',
20192019
'',
2020-
' alias of :class:`int`',
2020+
' alias of :py:class:`int`',
20212021
'',
20222022
'',
20232023
'.. py:data:: T7',
20242024
' :module: target.typevar',
20252025
'',
20262026
' T7',
20272027
'',
2028-
" alias of TypeVar('T7', bound=\\ :class:`int`)",
2028+
" alias of TypeVar('T7', bound=\\ :py:class:`int`)",
20292029
'',
20302030
]
20312031

tests/test_ext_autodoc_autoattribute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_autoattribute_GenericAlias(app):
167167
'',
168168
' A list of int',
169169
'',
170-
' alias of :class:`~typing.List`\\ [:class:`int`]',
170+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
171171
'',
172172
]
173173

@@ -182,7 +182,7 @@ def test_autoattribute_NewType(app):
182182
'',
183183
' T6',
184184
'',
185-
' alias of :class:`int`',
185+
' alias of :py:class:`int`',
186186
'',
187187
]
188188

tests/test_ext_autodoc_autoclass.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ def test_show_inheritance_for_subclass_of_generic_type(app):
265265
'.. py:class:: Quux(iterable=(), /)',
266266
' :module: target.classes',
267267
'',
268-
' Bases: :class:`~typing.List`\\ '
269-
'[:obj:`~typing.Union`\\ [:class:`int`, :class:`float`]]',
268+
' Bases: :py:class:`~typing.List`\\ '
269+
'[:py:obj:`~typing.Union`\\ [:py:class:`int`, :py:class:`float`]]',
270270
'',
271271
' A subclass of List[Union[int, float]]',
272272
'',
@@ -296,7 +296,7 @@ def autodoc_process_bases(app, name, obj, options, bases):
296296
'.. py:class:: Quux(*args, **kwds)',
297297
' :module: target.classes',
298298
'',
299-
' Bases: :class:`int`, :class:`str`',
299+
' Bases: :py:class:`int`, :py:class:`str`',
300300
'',
301301
' A subclass of List[Union[int, float]]',
302302
'',
@@ -307,7 +307,7 @@ def autodoc_process_bases(app, name, obj, options, bases):
307307
'.. py:class:: Quux(iterable=(), /)',
308308
' :module: target.classes',
309309
'',
310-
' Bases: :class:`int`, :class:`str`',
310+
' Bases: :py:class:`int`, :py:class:`str`',
311311
'',
312312
' A subclass of List[Union[int, float]]',
313313
'',
@@ -375,7 +375,7 @@ def autodoc_process_docstring(*args):
375375
'.. py:attribute:: Alias',
376376
' :module: target.classes',
377377
'',
378-
' alias of :class:`target.classes.Foo`',
378+
' alias of :py:class:`target.classes.Foo`',
379379
]
380380

381381

tests/test_ext_autodoc_autodata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_autodata_GenericAlias(app):
9696
'',
9797
' A list of int',
9898
'',
99-
' alias of :class:`~typing.List`\\ [:class:`int`]',
99+
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
100100
'',
101101
]
102102

@@ -111,7 +111,7 @@ def test_autodata_NewType(app):
111111
'',
112112
' T6',
113113
'',
114-
' alias of :class:`int`',
114+
' alias of :py:class:`int`',
115115
'',
116116
]
117117

0 commit comments

Comments
 (0)