Merge pull request #5308 from tk0miya/5306_warning_for_invalid_typehints

Fix #5306: autodoc: emit a warning for invalid typehints
This commit is contained in:
Takeshi KOMIYA 2018-08-18 12:05:59 +09:00 committed by GitHub
commit fa8b84a12f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -197,6 +197,7 @@ Features added
* #5246: Add :confval:`singlehtml_sidebars` to configure sidebars for singlehtml * #5246: Add :confval:`singlehtml_sidebars` to configure sidebars for singlehtml
builder builder
* #5273: doctest: Skip doctest conditionally * #5273: doctest: Skip doctest conditionally
* #5306: autodoc: emit a warning for invalid typehints
Bugs fixed Bugs fixed
---------- ----------

View File

@ -20,12 +20,15 @@ from six import PY2, PY3, StringIO, binary_type, string_types, itervalues
from six.moves import builtins from six.moves import builtins
from sphinx.util import force_decode from sphinx.util import force_decode
from sphinx.util import logging
from sphinx.util.pycompat import NoneType from sphinx.util.pycompat import NoneType
if False: if False:
# For type annotation # For type annotation
from typing import Any, Callable, Dict, List, Tuple, Type # NOQA from typing import Any, Callable, Dict, List, Tuple, Type # NOQA
logger = logging.getLogger(__name__)
memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE) memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE)
@ -339,7 +342,8 @@ class Signature(object):
try: try:
self.annotations = typing.get_type_hints(subject) # type: ignore self.annotations = typing.get_type_hints(subject) # type: ignore
except Exception: except Exception as exc:
logger.warning('Invalid type annotation found on %r. Ingored: %r', subject, exc)
self.annotations = {} self.annotations = {}
if bound_method: if bound_method: