Skip to content

Commit 7bee33a

Browse files
authored
MAINT: Updates related to xref (#292)
* TST: use default links in xref test. Switch to numpydoc's default link mapping for test_xref instead of the custom (less comprehensive) link mapping. * DOC: rm statements about xref_alias dict. Default aliases are not an empty dict, nor are they dependent on intersphinx. * DOC: Update make_xref docstring.
1 parent 4e86e81 commit 7bee33a

File tree

3 files changed

+31
-48
lines changed

3 files changed

+31
-48
lines changed

doc/install.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ numpydoc_xref_aliases : dict
6363
aliases/shortcuts used when specifying the types of parameters.
6464
The keys should not have any spaces. Together with the ``intersphinx``
6565
extension, you can map to links in any documentation.
66-
The default is an empty ``dict``.
67-
68-
If you have the following ``intersphinx`` namespace configuration::
69-
70-
intersphinx_mapping = {
71-
'python': ('https://docs.python.org/3/', None),
72-
'numpy': ('https://docs.scipy.org/doc/numpy', None),
73-
...
74-
}
7566

7667
The default ``numpydoc_xref_aliases`` will supply some common ``Python``
7768
standard library and ``NumPy`` names for you. Then for your module, a useful

numpydoc/tests/test_xref.py

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
# -*- encoding:utf-8 -*-
22
import pytest
3-
from numpydoc.xref import make_xref
4-
5-
xref_aliases = {
6-
# python
7-
'sequence': ':term:`python:sequence`',
8-
'iterable': ':term:`python:iterable`',
9-
'string': 'str',
10-
# numpy
11-
'array': 'numpy.ndarray',
12-
'dtype': 'numpy.dtype',
13-
'ndarray': 'numpy.ndarray',
14-
'matrix': 'numpy.matrix',
15-
'array-like': ':term:`numpy:array_like`',
16-
'array_like': ':term:`numpy:array_like`',
17-
}
3+
from numpydoc.xref import make_xref, DEFAULT_LINKS
4+
5+
# Use the default numpydoc link mapping
6+
xref_aliases = DEFAULT_LINKS
7+
188

199
# Comes mainly from numpy
2010
data = r"""
2111
(...) array_like, float, optional
22-
(...) :term:`numpy:array_like`, :obj:`float`, optional
12+
(...) :term:`numpy:array_like`, :class:`python:float`, optional
2313
2414
(2,) ndarray
2515
(2,) :obj:`ndarray <numpy.ndarray>`
@@ -31,37 +21,37 @@
3121
(..., :obj:`M`, :obj:`N`) :term:`numpy:array_like`
3222
3323
(float, float), optional
34-
(:obj:`float`, :obj:`float`), optional
24+
(:class:`python:float`, :class:`python:float`), optional
3525
3626
1-D array or sequence
3727
1-D :obj:`array <numpy.ndarray>` or :term:`python:sequence`
3828
3929
array of str or unicode-like
40-
:obj:`array <numpy.ndarray>` of :obj:`str` or unicode-like
30+
:obj:`array <numpy.ndarray>` of :class:`python:str` or unicode-like
4131
4232
array_like of float
43-
:term:`numpy:array_like` of :obj:`float`
33+
:term:`numpy:array_like` of :class:`python:float`
4434
4535
bool or callable
46-
:obj:`bool` or :obj:`callable`
36+
:ref:`bool <python:bltin-boolean-values>` or :func:`python:callable`
4737
4838
int in [0, 255]
49-
:obj:`int` in [0, 255]
39+
:class:`python:int` in [0, 255]
5040
5141
int or None, optional
52-
:obj:`int` or :obj:`None`, optional
42+
:class:`python:int` or :data:`python:None`, optional
5343
5444
list of str or array_like
55-
:obj:`list` of :obj:`str` or :term:`numpy:array_like`
45+
:class:`python:list` of :class:`python:str` or :term:`numpy:array_like`
5646
5747
sequence of array_like
5848
:term:`python:sequence` of :term:`numpy:array_like`
5949
6050
str or pathlib.Path
61-
:obj:`str` or :obj:`pathlib.Path`
51+
:class:`python:str` or :obj:`pathlib.Path`
6252
6353
{'', string}, optional
64-
{'', :obj:`string <str>`}, optional
54+
{'', :class:`python:str`}, optional
6555
6656
{'C', 'F', 'A', or 'K'}, optional
6757
{'C', 'F', 'A', or 'K'}, optional
@@ -70,16 +60,16 @@
7060
{'linear', 'lower', 'higher', 'midpoint', 'nearest'}
7161
7262
{False, True, 'greedy', 'optimal'}
73-
{:obj:`False`, :obj:`True`, 'greedy', 'optimal'}
63+
{:data:`python:False`, :data:`python:True`, 'greedy', 'optimal'}
7464
7565
{{'begin', 1}, {'end', 0}}, {string, int}
76-
{{'begin', 1}, {'end', 0}}, {:obj:`string <str>`, :obj:`int`}
66+
{{'begin', 1}, {'end', 0}}, {:class:`python:str`, :class:`python:int`}
7767
7868
callable f'(x,*args)
79-
:obj:`callable` f'(x,*args)
69+
:func:`python:callable` f'(x,*args)
8070
8171
callable ``fhess(x, *args)``, optional
82-
:obj:`callable` ``fhess(x, *args)``, optional
72+
:func:`python:callable` ``fhess(x, *args)``, optional
8373
8474
spmatrix (format: ``csr``, ``bsr``, ``dia`` or coo``)
8575
:obj:`spmatrix` (format: ``csr``, ``bsr``, ``dia`` or coo``)
@@ -88,28 +78,28 @@
8878
:ref:`strftime <strftime-strptime-behavior>`
8979
9080
callable or :ref:`strftime <strftime-strptime-behavior>`
91-
:obj:`callable` or :ref:`strftime <strftime-strptime-behavior>`
81+
:func:`python:callable` or :ref:`strftime <strftime-strptime-behavior>`
9282
9383
callable or :ref:`strftime behavior <strftime-strptime-behavior>`
94-
:obj:`callable` or :ref:`strftime behavior <strftime-strptime-behavior>`
84+
:func:`python:callable` or :ref:`strftime behavior <strftime-strptime-behavior>`
9585
9686
list(int)
97-
:obj:`list`\(:obj:`int`)
87+
:class:`python:list`\(:class:`python:int`)
9888
9989
list[int]
100-
:obj:`list`\[:obj:`int`]
90+
:class:`python:list`\[:class:`python:int`]
10191
10292
dict(str, int)
103-
:obj:`dict`\(:obj:`str`, :obj:`int`)
93+
:class:`python:dict`\(:class:`python:str`, :class:`python:int`)
10494
10595
dict[str, int]
106-
:obj:`dict`\[:obj:`str`, :obj:`int`]
96+
:class:`python:dict`\[:class:`python:str`, :class:`python:int`]
10797
10898
tuple(float, float)
109-
:obj:`tuple`\(:obj:`float`, :obj:`float`)
99+
:class:`python:tuple`\(:class:`python:float`, :class:`python:float`)
110100
111101
dict[tuple(str, str), int]
112-
:obj:`dict`\[:obj:`tuple`\(:obj:`str`, :obj:`str`), :obj:`int`]
102+
:class:`python:dict`\[:class:`python:tuple`\(:class:`python:str`, :class:`python:str`), :class:`python:int`]
113103
""" # noqa: E501
114104

115105
xref_ignore = {'or', 'in', 'of', 'default', 'optional'}

numpydoc/xref.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@
9595

9696

9797
def make_xref(param_type, xref_aliases, xref_ignore):
98-
"""Enclose str in a :obj: role.
98+
"""Parse and apply appropriate sphinx role(s) to `param_type`.
99+
100+
The :obj: role is the default.
99101
100102
Parameters
101103
----------
@@ -110,7 +112,7 @@ def make_xref(param_type, xref_aliases, xref_ignore):
110112
Returns
111113
-------
112114
out : str
113-
Text with parts that may be wrapped in a
115+
Text with fully-qualified names and terms that may be wrapped in a
114116
``:obj:`` role.
115117
"""
116118
if param_type in xref_aliases:

0 commit comments

Comments
 (0)