Skip to content

Commit b1c99e8

Browse files
committed
Merge branch '4.x' into 10009_exception_on_getdoc
2 parents 10efd31 + 8ddf3f0 commit b1c99e8

File tree

150 files changed

+5022
-4952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+5022
-4952
lines changed

CHANGES

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Release 4.4.0 (in development)
44
Dependencies
55
------------
66

7+
* #10007: Use ``importlib_metadata`` for python-3.9 or older
8+
* #10007: Drop ``setuptools``
9+
710
Incompatible changes
811
--------------------
912

@@ -13,7 +16,7 @@ Deprecated
1316
Features added
1417
--------------
1518

16-
* #9075: autodoc: Add a config variable :confval:`autodoc_unqualified_typehints`
19+
* #9075: autodoc: Add a config variable :confval:`autodoc_typehints_format`
1720
to suppress the leading module names of typehints of function signatures (ex.
1821
``io.StringIO`` -> ``StringIO``)
1922
* #9831: Autosummary now documents only the members specified in a module's
@@ -46,6 +49,7 @@ Bugs fixed
4649
with Python 3.10
4750
* #9968: autodoc: instance variables are not shown if __init__ method has
4851
position-only-arguments
52+
* #9194: autodoc: types under the "typing" module are not hyperlinked
4953
* #10009: autodoc: Crashes if target object raises an error on getting docstring
5054
* #9947: i18n: topic directive having a bullet list can't be translatable
5155
* #9878: mathjax: MathJax configuration is placed after loading MathJax itself

doc/usage/extensions/autodoc.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,15 @@ There are also config values that you can set:
662662
.. __: https://mypy.readthedocs.io/en/latest/kinds_of_types.html#type-aliases
663663
.. versionadded:: 3.3
664664

665-
.. confval:: autodoc_unqualified_typehints
665+
.. confval:: autodoc_typehints_format
666666

667-
If True, the leading module names of typehints of function signatures are
668-
removed (ex. ``io.StringIO`` -> ``StringIO``). Defaults to False.
667+
This value controls the format of typehints. The setting takes the
668+
following values:
669+
670+
* ``'fully-qualified'`` -- Show the module name and its name of typehints
671+
(default)
672+
* ``'short'`` -- Suppress the leading module names of the typehints
673+
(ex. ``io.StringIO`` -> ``StringIO``)
669674

670675
.. versionadded:: 4.4
671676

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
'alabaster>=0.7,<0.8',
3030
'imagesize',
3131
'requests>=2.5.0',
32-
'setuptools',
3332
'packaging',
33+
"importlib-metadata>=4.4; python_version < '3.10'",
3434
]
3535

3636
extras_require = {
@@ -47,7 +47,6 @@
4747
'mypy>=0.930',
4848
'docutils-stubs',
4949
"types-typed-ast",
50-
"types-pkg_resources",
5150
"types-requests",
5251
],
5352
'test': [

sphinx/application.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -933,14 +933,18 @@ def add_post_transform(self, transform: Type[Transform]) -> None:
933933
def add_js_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
934934
"""Register a JavaScript file to include in the HTML output.
935935
936-
Add *filename* to the list of JavaScript files that the default HTML
937-
template will include in order of *priority* (ascending). The filename
938-
must be relative to the HTML static path , or a full URI with scheme.
939-
If the priority of the JavaScript file is the same as others, the JavaScript
940-
files will be included in order of registration. If the keyword
941-
argument ``body`` is given, its value will be added between the
942-
``<script>`` tags. Extra keyword arguments are included as attributes of
943-
the ``<script>`` tag.
936+
:param filename: The filename of the JavaScript file. It must be relative to the HTML
937+
static path, a full URI with scheme, or ``None`` value. The ``None``
938+
value is used to create inline ``<script>`` tag. See the description
939+
of *kwargs* below.
940+
:param priority: The priority to determine the order of ``<script>`` tag for
941+
JavaScript files. See list of "prority range for JavaScript
942+
files" below. If the priority of the JavaScript files it the same
943+
as others, the JavaScript files will be loaded in order of
944+
registration.
945+
:param kwargs: Extra keyword arguments are included as attributes of the ``<script>``
946+
tag. A special keyword argument ``body`` is given, its value will be
947+
added between the ``<script>`` tag.
944948
945949
Example::
946950
@@ -984,12 +988,14 @@ def add_js_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None
984988
def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
985989
"""Register a stylesheet to include in the HTML output.
986990
987-
Add *filename* to the list of CSS files that the default HTML template
988-
will include in order of *priority* (ascending). The filename must be
989-
relative to the HTML static path, or a full URI with scheme. If the
990-
priority of the CSS file is the same as others, the CSS files will be
991-
included in order of registration. The keyword arguments are also
992-
accepted for attributes of ``<link>`` tag.
991+
:param filename: The filename of the CSS file. It must be relative to the HTML
992+
static path, or a full URI with scheme.
993+
:param priority: The priority to determine the order of ``<link>`` tag for the
994+
CSS files. See list of "prority range for CSS files" below.
995+
If the priority of the CSS files it the same as others, the
996+
CSS files will be loaded in order of registration.
997+
:param kwargs: Extra keyword arguments are included as attributes of the ``<link>``
998+
tag.
993999
9941000
Example::
9951001

sphinx/domains/python.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class ModuleEntry(NamedTuple):
8383
def type_to_xref(target: str, env: BuildEnvironment = None, suppress_prefix: bool = False
8484
) -> addnodes.pending_xref:
8585
"""Convert a type string to a cross reference node."""
86-
if target == 'None':
86+
if target == 'None' or target.startswith('typing.'):
87+
# typing module provides non-class types. Obj reference is good to refer them.
8788
reftype = 'obj'
8889
else:
8990
reftype = 'class'
@@ -104,6 +105,8 @@ def type_to_xref(target: str, env: BuildEnvironment = None, suppress_prefix: boo
104105
text = target.split('.')[-1]
105106
elif suppress_prefix:
106107
text = target.split('.')[-1]
108+
elif target.startswith('typing.'):
109+
text = target[7:]
107110
else:
108111
text = target
109112

@@ -203,10 +206,16 @@ def unparse(node: ast.AST) -> List[Node]:
203206
return result
204207
else:
205208
if sys.version_info < (3, 8):
206-
if isinstance(node, ast.Ellipsis):
209+
if isinstance(node, ast.Bytes):
210+
return [addnodes.desc_sig_literal_string('', repr(node.s))]
211+
elif isinstance(node, ast.Ellipsis):
207212
return [addnodes.desc_sig_punctuation('', "...")]
208213
elif isinstance(node, ast.NameConstant):
209214
return [nodes.Text(node.value)]
215+
elif isinstance(node, ast.Num):
216+
return [addnodes.desc_sig_literal_string('', repr(node.n))]
217+
elif isinstance(node, ast.Str):
218+
return [addnodes.desc_sig_literal_string('', repr(node.s))]
210219

211220
raise SyntaxError # unsupported syntax
212221

@@ -1481,7 +1490,7 @@ def istyping(s: str) -> bool:
14811490
return None
14821491
elif node.get('reftype') in ('class', 'obj') and node.get('reftarget') == 'None':
14831492
return contnode
1484-
elif node.get('reftype') in ('class', 'exc'):
1493+
elif node.get('reftype') in ('class', 'obj', 'exc'):
14851494
reftarget = node.get('reftarget')
14861495
if inspect.isclass(getattr(builtins, reftarget, None)):
14871496
# built-in class

sphinx/ext/autodoc/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ def can_document_member(cls, member: Any, membername: str, isattr: bool, parent:
12971297
def format_args(self, **kwargs: Any) -> str:
12981298
if self.config.autodoc_typehints in ('none', 'description'):
12991299
kwargs.setdefault('show_annotation', False)
1300-
if self.config.autodoc_unqualified_typehints:
1300+
if self.config.autodoc_typehints_format == "short":
13011301
kwargs.setdefault('unqualified_typehints', True)
13021302

13031303
try:
@@ -1327,7 +1327,7 @@ def add_directive_header(self, sig: str) -> None:
13271327
self.add_line(' :async:', sourcename)
13281328

13291329
def format_signature(self, **kwargs: Any) -> str:
1330-
if self.config.autodoc_unqualified_typehints:
1330+
if self.config.autodoc_typehints_format == "short":
13311331
kwargs.setdefault('unqualified_typehints', True)
13321332

13331333
sigs = []
@@ -1568,7 +1568,7 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
15681568
def format_args(self, **kwargs: Any) -> str:
15691569
if self.config.autodoc_typehints in ('none', 'description'):
15701570
kwargs.setdefault('show_annotation', False)
1571-
if self.config.autodoc_unqualified_typehints:
1571+
if self.config.autodoc_typehints_format == "short":
15721572
kwargs.setdefault('unqualified_typehints', True)
15731573

15741574
try:
@@ -1591,7 +1591,7 @@ def format_signature(self, **kwargs: Any) -> str:
15911591
# do not show signatures
15921592
return ''
15931593

1594-
if self.config.autodoc_unqualified_typehints:
1594+
if self.config.autodoc_typehints_format == "short":
15951595
kwargs.setdefault('unqualified_typehints', True)
15961596

15971597
sig = super().format_signature()
@@ -2122,7 +2122,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
21222122
def format_args(self, **kwargs: Any) -> str:
21232123
if self.config.autodoc_typehints in ('none', 'description'):
21242124
kwargs.setdefault('show_annotation', False)
2125-
if self.config.autodoc_unqualified_typehints:
2125+
if self.config.autodoc_typehints_format == "short":
21262126
kwargs.setdefault('unqualified_typehints', True)
21272127

21282128
try:
@@ -2174,7 +2174,7 @@ def document_members(self, all_members: bool = False) -> None:
21742174
pass
21752175

21762176
def format_signature(self, **kwargs: Any) -> str:
2177-
if self.config.autodoc_unqualified_typehints:
2177+
if self.config.autodoc_typehints_format == "short":
21782178
kwargs.setdefault('unqualified_typehints', True)
21792179

21802180
sigs = []
@@ -2850,7 +2850,8 @@ def setup(app: Sphinx) -> Dict[str, Any]:
28502850
app.add_config_value('autodoc_typehints_description_target', 'all', True,
28512851
ENUM('all', 'documented'))
28522852
app.add_config_value('autodoc_type_aliases', {}, True)
2853-
app.add_config_value('autodoc_unqualified_typehints', False, 'env')
2853+
app.add_config_value('autodoc_typehints_format', "fully-qualified", 'env',
2854+
ENUM("fully-qualified", "short"))
28542855
app.add_config_value('autodoc_warningiserror', True, True)
28552856
app.add_config_value('autodoc_inherit_docstrings', True, True)
28562857
app.add_event('autodoc-before-process-signature')

sphinx/locale/.tx/config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ host = https://www.transifex.com
55
file_filter = <lang>/LC_MESSAGES/sphinx.po
66
source_file = sphinx.pot
77
source_lang = en
8-
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)