Skip to content

Commit

Permalink
Merge branch '3.x' into 7964_tuple_in_signature
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Oct 4, 2020
2 parents 785f4d6 + b428cd2 commit 3096b71
Show file tree
Hide file tree
Showing 102 changed files with 399 additions and 216 deletions.
8 changes: 6 additions & 2 deletions CHANGES
Expand Up @@ -34,14 +34,18 @@ Bugs fixed
by string not ending with blank lines
* #8142: autodoc: Wrong constructor signature for the class derived from
typing.Generic
* #8157: autodoc: TypeError is raised when annotation has invalid __args__
* #7964: autodoc: Tuple in default value is wrongly rendered
* #8192: napoleon: description is disappeared when it contains inline literals
* #8142: napoleon: Potential of regex denial of service in google style docs
* #8169: LaTeX: pxjahyper loaded even when latex_engine is not platex
* #8175: intersphinx: Potential of regex denial of service by broken inventory
* #8277: sphinx-build: missing and redundant spacing (and etc) for console
output on building
* #8093: The highlight warning has wrong location in some builders (LaTeX,
singlehtml and so on)
* #8239: Failed to refer a token in productionlist if it is indented
* #8268: linkcheck: Report HTTP errors when ``linkcheck_anchors`` is ``True``

Testing
--------
Expand Down Expand Up @@ -172,7 +176,7 @@ Bugs fixed
contains a hyperlink target
* #7469: autosummary: "Module attributes" header is not translatable
* #7940: apidoc: An extra newline is generated at the end of the rst file if a
module has submodules
module has submodules
* #4258: napoleon: decorated special methods are not shown
* #7799: napoleon: parameters are not escaped for combined params in numpydoc
* #7780: napoleon: multiple paramaters declaration in numpydoc was wrongly
Expand Down Expand Up @@ -339,7 +343,7 @@ Features added
* #7543: html theme: Add top and bottom margins to tables
* #7695: html theme: Add viewport meta tag for basic theme
* #7721: html theme: classic: default codetextcolor/codebgcolor doesn't override
Pygments
Pygments
* C and C++: allow semicolon in the end of declarations.
* C++, parse parameterized noexcept specifiers.
* #7294: C++, parse expressions with user-defined literals.
Expand Down
2 changes: 1 addition & 1 deletion doc/_themes/sphinx13/static/sphinx13.css
Expand Up @@ -239,7 +239,7 @@ div.footer a {

/* -- body styles ----------------------------------------------------------- */

p {
p {
margin: 0.8em 0 0.5em 0;
}

Expand Down
38 changes: 38 additions & 0 deletions doc/usage/extensions/autodoc.rst
Expand Up @@ -515,6 +515,44 @@ There are also config values that you can set:

New option ``'description'`` is added.

.. confval:: autodoc_type_aliases

A dictionary for users defined `type aliases`__ that maps a type name to the
full-qualified object name. It is used to keep type aliases not evaluated in
the document. Defaults to empty (``{}``).

The type aliases are only available if your program enables `Postponed
Evaluation of Annotations (PEP 563)`__ feature via ``from __future__ import
annotations``.

For example, there is code using a type alias::

from __future__ import annotations

AliasType = Union[List[Dict[Tuple[int, str], Set[int]]], Tuple[str, List[str]]]

def f() -> AliasType:
...

If ``autodoc_type_aliases`` is not set, autodoc will generate internal mark-up
from this code as following::

.. py:function:: f() -> Union[List[Dict[Tuple[int, str], Set[int]]], Tuple[str, List[str]]]

...

If you set ``autodoc_type_aliases`` as
``{'AliasType': 'your.module.TypeAlias'}``, it generates a following document
internally::

.. py:function:: f() -> your.module.AliasType:

...

.. __: https://www.python.org/dev/peps/pep-0563/
.. __: https://mypy.readthedocs.io/en/latest/kinds_of_types.html#type-aliases
.. versionadded:: 3.3

.. confval:: autodoc_warningiserror

This value controls the behavior of :option:`sphinx-build -W` during
Expand Down
2 changes: 1 addition & 1 deletion doc/usage/extensions/coverage.rst
Expand Up @@ -51,7 +51,7 @@ should check:

.. versionadded:: 1.1

.. confval:: coverage_show_missing_items
.. confval:: coverage_show_missing_items

Print objects that are missing to standard output also.
``False`` by default.
Expand Down
2 changes: 1 addition & 1 deletion doc/usage/installation.rst
Expand Up @@ -171,7 +171,7 @@ Docker images for Sphinx are published on the `Docker Hub <https://hub.docker.co
- `sphinxdoc/sphinx <https://hub.docker.com/repository/docker/sphinxdoc/sphinx>`_
- `sphinxdoc/sphinx-latexpdf <https://hub.docker.com/repository/docker/sphinxdoc/sphinx-latexpdf>`_

Former one is used for standard usage of Sphinx, and latter one is mainly used for PDF builds using LaTeX.
Former one is used for standard usage of Sphinx, and latter one is mainly used for PDF builds using LaTeX.
Please choose one for your purpose.

.. note::
Expand Down
4 changes: 2 additions & 2 deletions doc/usage/restructuredtext/directives.rst
Expand Up @@ -665,7 +665,7 @@ __ http://pygments.org/docs/lexers
.. note::

If you want to select only ``[second-section]`` of ini file like the
following, you can use ``:start-at: [second-section]`` and
following, you can use ``:start-at: [second-section]`` and
``:end-before: [third-section]``:

.. code-block:: ini
Expand All @@ -692,7 +692,7 @@ __ http://pygments.org/docs/lexers
# [initialize]
app.start(":8000")
# [initialize]
When lines have been selected in any of the ways described above, the line
numbers in ``emphasize-lines`` refer to those selected lines, counted
Expand Down
12 changes: 6 additions & 6 deletions sphinx/builders/html/__init__.py
Expand Up @@ -641,17 +641,17 @@ def gen_pages_from_extensions(self) -> None:
def gen_additional_pages(self) -> None:
# additional pages from conf.py
for pagename, template in self.config.html_additional_pages.items():
logger.info(' ' + pagename, nonl=True)
logger.info(pagename + ' ', nonl=True)
self.handle_page(pagename, {}, template)

# the search page
if self.search:
logger.info(' search', nonl=True)
logger.info('search ', nonl=True)
self.handle_page('search', {}, 'search.html')

# the opensearch xml file
if self.config.html_use_opensearch and self.search:
logger.info(' opensearch', nonl=True)
logger.info('opensearch ', nonl=True)
fn = path.join(self.outdir, '_static', 'opensearch.xml')
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)

Expand All @@ -669,7 +669,7 @@ def write_genindex(self) -> None:
'genindexcounts': indexcounts,
'split_index': self.config.html_split_index,
}
logger.info(' genindex', nonl=True)
logger.info('genindex ', nonl=True)

if self.config.html_split_index:
self.handle_page('genindex', genindexcontext,
Expand All @@ -691,7 +691,7 @@ def write_domain_indices(self) -> None:
'content': content,
'collapse_index': collapse,
}
logger.info(' ' + indexname, nonl=True)
logger.info(indexname + ' ', nonl=True)
self.handle_page(indexname, indexcontext, 'domainindex.html')

def copy_image_files(self) -> None:
Expand Down Expand Up @@ -785,7 +785,7 @@ def copy_html_favicon(self) -> None:

def copy_static_files(self) -> None:
try:
with progress_message(__('copying static files... ')):
with progress_message(__('copying static files')):
ensuredir(path.join(self.outdir, '_static'))

# prepare context for templates
Expand Down
4 changes: 2 additions & 2 deletions sphinx/builders/latex/__init__.py
Expand Up @@ -517,7 +517,7 @@ def validate_latex_theme_options(app: Sphinx, config: Config) -> None:
config.latex_theme_options.pop(key)


def install_pakcages_for_ja(app: Sphinx) -> None:
def install_packages_for_ja(app: Sphinx) -> None:
"""Install packages for Japanese."""
if app.config.language == 'ja' and app.config.latex_engine in ('platex', 'uplatex'):
app.add_latex_package('pxjahyper', after_hyperref=True)
Expand Down Expand Up @@ -570,7 +570,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_builder(LaTeXBuilder)
app.connect('config-inited', validate_config_values, priority=800)
app.connect('config-inited', validate_latex_theme_options, priority=800)
app.connect('builder-inited', install_pakcages_for_ja)
app.connect('builder-inited', install_packages_for_ja)

app.add_config_value('latex_engine', default_latex_engine, None,
ENUM('pdflatex', 'xelatex', 'lualatex', 'platex', 'uplatex'))
Expand Down
1 change: 1 addition & 0 deletions sphinx/builders/linkcheck.py
Expand Up @@ -166,6 +166,7 @@ def check_uri() -> Tuple[str, str, int]:
# Read the whole document and see if #anchor exists
response = requests.get(req_url, stream=True, config=self.app.config,
auth=auth_info, **kwargs)
response.raise_for_status()
found = check_anchor(response, unquote(anchor))

if not found:
Expand Down
37 changes: 25 additions & 12 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1213,7 +1213,8 @@ def format_args(self, **kwargs: Any) -> str:

try:
self.env.app.emit('autodoc-before-process-signature', self.object, False)
sig = inspect.signature(self.object, follow_wrapped=True)
sig = inspect.signature(self.object, follow_wrapped=True,
type_aliases=self.env.config.autodoc_type_aliases)
args = stringify_signature(sig, **kwargs)
except TypeError as exc:
logger.warning(__("Failed to get a function signature for %s: %s"),
Expand Down Expand Up @@ -1262,7 +1263,9 @@ def format_signature(self, **kwargs: Any) -> str:
if overloaded:
__globals__ = safe_getattr(self.object, '__globals__', {})
for overload in self.analyzer.overloads.get('.'.join(self.objpath)):
overload = evaluate_signature(overload, __globals__)
overload = evaluate_signature(overload, __globals__,
self.env.config.autodoc_type_aliases)

sig = stringify_signature(overload, **kwargs)
sigs.append(sig)

Expand All @@ -1271,7 +1274,7 @@ def format_signature(self, **kwargs: Any) -> str:
def annotate_to_first_argument(self, func: Callable, typ: Type) -> None:
"""Annotate type hint to the first argument of function if needed."""
try:
sig = inspect.signature(func)
sig = inspect.signature(func, type_aliases=self.env.config.autodoc_type_aliases)
except TypeError as exc:
logger.warning(__("Failed to get a function signature for %s: %s"),
self.fullname, exc)
Expand Down Expand Up @@ -1392,7 +1395,8 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
if call is not None:
self.env.app.emit('autodoc-before-process-signature', call, True)
try:
sig = inspect.signature(call, bound_method=True)
sig = inspect.signature(call, bound_method=True,
type_aliases=self.env.config.autodoc_type_aliases)
return type(self.object), '__call__', sig
except ValueError:
pass
Expand All @@ -1407,7 +1411,8 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
if new is not None:
self.env.app.emit('autodoc-before-process-signature', new, True)
try:
sig = inspect.signature(new, bound_method=True)
sig = inspect.signature(new, bound_method=True,
type_aliases=self.env.config.autodoc_type_aliases)
return self.object, '__new__', sig
except ValueError:
pass
Expand All @@ -1417,7 +1422,8 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
if init is not None:
self.env.app.emit('autodoc-before-process-signature', init, True)
try:
sig = inspect.signature(init, bound_method=True)
sig = inspect.signature(init, bound_method=True,
type_aliases=self.env.config.autodoc_type_aliases)
return self.object, '__init__', sig
except ValueError:
pass
Expand All @@ -1428,7 +1434,8 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
# the signature from, so just pass the object itself to our hook.
self.env.app.emit('autodoc-before-process-signature', self.object, False)
try:
sig = inspect.signature(self.object, bound_method=False)
sig = inspect.signature(self.object, bound_method=False,
type_aliases=self.env.config.autodoc_type_aliases)
return None, None, sig
except ValueError:
pass
Expand Down Expand Up @@ -1475,7 +1482,8 @@ def format_signature(self, **kwargs: Any) -> str:
method = safe_getattr(self._signature_class, self._signature_method_name, None)
__globals__ = safe_getattr(method, '__globals__', {})
for overload in self.analyzer.overloads.get(qualname):
overload = evaluate_signature(overload, __globals__)
overload = evaluate_signature(overload, __globals__,
self.env.config.autodoc_type_aliases)

parameters = list(overload.parameters.values())
overload = overload.replace(parameters=parameters[1:],
Expand Down Expand Up @@ -1820,11 +1828,13 @@ def format_args(self, **kwargs: Any) -> str:
else:
if inspect.isstaticmethod(self.object, cls=self.parent, name=self.object_name):
self.env.app.emit('autodoc-before-process-signature', self.object, False)
sig = inspect.signature(self.object, bound_method=False)
sig = inspect.signature(self.object, bound_method=False,
type_aliases=self.env.config.autodoc_type_aliases)
else:
self.env.app.emit('autodoc-before-process-signature', self.object, True)
sig = inspect.signature(self.object, bound_method=True,
follow_wrapped=True)
follow_wrapped=True,
type_aliases=self.env.config.autodoc_type_aliases)
args = stringify_signature(sig, **kwargs)
except TypeError as exc:
logger.warning(__("Failed to get a method signature for %s: %s"),
Expand Down Expand Up @@ -1884,7 +1894,9 @@ def format_signature(self, **kwargs: Any) -> str:
if overloaded:
__globals__ = safe_getattr(self.object, '__globals__', {})
for overload in self.analyzer.overloads.get('.'.join(self.objpath)):
overload = evaluate_signature(overload, __globals__)
overload = evaluate_signature(overload, __globals__,
self.env.config.autodoc_type_aliases)

if not inspect.isstaticmethod(self.object, cls=self.parent,
name=self.object_name):
parameters = list(overload.parameters.values())
Expand All @@ -1897,7 +1909,7 @@ def format_signature(self, **kwargs: Any) -> str:
def annotate_to_first_argument(self, func: Callable, typ: Type) -> None:
"""Annotate type hint to the first argument of function if needed."""
try:
sig = inspect.signature(func)
sig = inspect.signature(func, type_aliases=self.env.config.autodoc_type_aliases)
except TypeError as exc:
logger.warning(__("Failed to get a method signature for %s: %s"),
self.fullname, exc)
Expand Down Expand Up @@ -2237,6 +2249,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('autodoc_mock_imports', [], True)
app.add_config_value('autodoc_typehints', "signature", True,
ENUM("signature", "description", "none"))
app.add_config_value('autodoc_type_aliases', {}, True)
app.add_config_value('autodoc_warningiserror', True, True)
app.add_config_value('autodoc_inherit_docstrings', True, True)
app.add_event('autodoc-before-process-signature')
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/ar/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# Mohammed Shannaq <sam@ms.per.jo>, 2018
msgid ""
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/bg/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
msgid ""
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/bn/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# FIRST AUTHOR <EMAIL@ADDRESS>, 2009
msgid ""
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/ca/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# FIRST AUTHOR <EMAIL@ADDRESS>, 2009
msgid ""
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/cak/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# Julien Malard <julien.malard@mail.mcgill.ca>, 2019
msgid ""
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/cs/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# FIRST AUTHOR <EMAIL@ADDRESS>, 2008
# Vilibald W. <vilibald.wanca@gmail.com>, 2014-2015
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/cy/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016
# Geraint Palmer <palmer.geraint@googlemail.com>, 2016
Expand Down
2 changes: 1 addition & 1 deletion sphinx/locale/da/LC_MESSAGES/sphinx.po
@@ -1,7 +1,7 @@
# Translations template for Sphinx.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the Sphinx project.
#
#
# Translators:
# askhl <asklarsen@gmail.com>, 2010-2011
# Jakob Lykke Andersen <jakob@caput.dk>, 2014,2016
Expand Down

0 comments on commit 3096b71

Please sign in to comment.