From bde53bf9fbdf612a48adf377c15c03a5e31113da Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 22 Aug 2018 15:28:16 +0900 Subject: [PATCH 1/4] Fix #5320: intersphinx: crashed if invalid url given --- CHANGES | 2 ++ sphinx/ext/intersphinx.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 5f6bbaf8d..94f7fce05 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #5320: intersphinx: crashed if invalid url given + Testing -------- diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 372f7baab..88e9997eb 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -403,14 +403,19 @@ def inspect_main(argv): def warn(self, msg): print(msg, file=sys.stderr) - filename = argv[0] - invdata = fetch_inventory(MockApp(), '', filename) # type: ignore - for key in sorted(invdata or {}): - print(key) - for entry, einfo in sorted(invdata[key].items()): - print('\t%-40s %s%s' % (entry, - einfo[3] != '-' and '%-40s: ' % einfo[3] or '', - einfo[2])) + try: + filename = argv[0] + invdata = fetch_inventory(MockApp(), '', filename) # type: ignore + for key in sorted(invdata or {}): + print(key) + for entry, einfo in sorted(invdata[key].items()): + print('\t%-40s %s%s' % (entry, + einfo[3] != '-' and '%-40s: ' % einfo[3] or '', + einfo[2])) + except ValueError as exc: + print(exc.args[0] % exc.args[1:]) + except Exception as exc: + print('Unknown error: %r' % exc) if __name__ == '__main__': From 59a766d7d69d072ee5cf90455f52ff0d169b4442 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 21 Aug 2018 20:05:17 +0900 Subject: [PATCH 2/4] Fix #5322: autodoc: ``Any`` typehint causes formatting error --- CHANGES | 2 ++ sphinx/util/inspect.py | 4 +++- tests/test_util_inspect.py | 6 +++++- tests/typing_test_data.py | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 5f6bbaf8d..798187983 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #5322: autodoc: ``Any`` typehint causes formatting error + Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 3b5d48e2a..bab88eb88 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -531,8 +531,10 @@ class Signature(object): qualname = annotation.__qualname__ elif getattr(annotation, '__forward_arg__', None): qualname = annotation.__forward_arg__ - else: + elif getattr(annotation, '__origin__', None): qualname = self.format_annotation(annotation.__origin__) # ex. Union + else: + qualname = repr(annotation).replace('typing.', '') elif hasattr(annotation, '__qualname__'): qualname = '%s.%s' % (module, annotation.__qualname__) else: diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index a48aedcf0..928a45621 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -232,7 +232,7 @@ def test_Signature_partialmethod(): reason='type annotation test is available on py34 or above') def test_Signature_annotations(): from typing_test_data import ( - f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, Node) + f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, Node) # Class annotations sig = inspect.Signature(f0).format_args() @@ -293,6 +293,10 @@ def test_Signature_annotations(): sig = inspect.Signature(f13).format_args() assert sig == '() -> Optional[str]' + # Any + sig = inspect.Signature(f14).format_args() + assert sig == '() -> Any' + # type hints by string sig = inspect.Signature(Node.children).format_args() assert sig == '(self) -> List[typing_test_data.Node]' diff --git a/tests/typing_test_data.py b/tests/typing_test_data.py index 5b161eac4..4dc2d06f5 100644 --- a/tests/typing_test_data.py +++ b/tests/typing_test_data.py @@ -1,5 +1,5 @@ from numbers import Integral -from typing import List, TypeVar, Union, Callable, Tuple, Optional +from typing import Any, List, TypeVar, Union, Callable, Tuple, Optional def f0(x: int, y: Integral) -> None: @@ -72,6 +72,10 @@ def f13() -> Optional[str]: pass +def f14() -> Any: + pass + + class Node: def __init__(self, parent: Optional['Node']) -> None: pass From ee604144c6ad09979820647e938138ad021e62b0 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 22 Aug 2018 19:48:43 +0900 Subject: [PATCH 3/4] Fix #5326: manpage: crashed when invalid docname is specified as ``man_pages`` --- CHANGES | 3 +++ sphinx/builders/manpage.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index 5f6bbaf8d..275a895ef 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #5326: manpage: crashed when invalid docname is specified as ``man_pages`` + + Testing -------- diff --git a/sphinx/builders/manpage.py b/sphinx/builders/manpage.py index 7a691ccf0..03462be6b 100644 --- a/sphinx/builders/manpage.py +++ b/sphinx/builders/manpage.py @@ -18,6 +18,7 @@ from six import string_types from sphinx import addnodes from sphinx.builders import Builder from sphinx.environment import NoUri +from sphinx.locale import __ from sphinx.util import logging from sphinx.util.console import bold, darkgreen # type: ignore from sphinx.util.nodes import inline_all_toctrees @@ -72,6 +73,10 @@ class ManualPageBuilder(Builder): for info in self.config.man_pages: docname, name, description, authors, section = info + if docname not in self.env.all_docs: + logger.warning(__('"man_pages" config value references unknown ' + 'document %s'), docname) + continue if isinstance(authors, string_types): if authors: authors = [authors] From 520797a5e8c52f9bdcdcf8cd85484b4c7d0ed21f Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 25 Aug 2018 02:21:39 +0900 Subject: [PATCH 4/4] test: Upgrade python on Circle CI to 3.5 --- .circleci/config.yml | 6 +++--- tests/test_util_inspect.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f4d4415f1..d349db6e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,6 @@ jobs: working_directory: /sphinx steps: - checkout - - run: /python3.4/bin/pip install -U pip setuptools - - run: /python3.4/bin/pip install -U .[test,websupport] - - run: make test PYTHON=/python3.4/bin/python + - run: /python3.5/bin/pip install -U pip setuptools + - run: /python3.5/bin/pip install -U .[test,websupport] + - run: make test PYTHON=/python3.5/bin/python diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 928a45621..eddca6241 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -299,7 +299,10 @@ def test_Signature_annotations(): # type hints by string sig = inspect.Signature(Node.children).format_args() - assert sig == '(self) -> List[typing_test_data.Node]' + if (3, 5, 0) <= sys.version_info < (3, 5, 3): + assert sig == '(self) -> List[Node]' + else: + assert sig == '(self) -> List[typing_test_data.Node]' sig = inspect.Signature(Node.__init__).format_args() assert sig == '(self, parent: Optional[Node]) -> None'