diff --git a/CHANGES b/CHANGES index b1c4d201b..67b386fe3 100644 --- a/CHANGES +++ b/CHANGES @@ -197,6 +197,7 @@ Features added * #5246: Add :confval:`singlehtml_sidebars` to configure sidebars for singlehtml builder * #5273: doctest: Skip doctest conditionally +* #5306: autodoc: emit a warning for invalid typehints Bugs fixed ---------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 9898506cc..487b95f1f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -20,12 +20,15 @@ from six import PY2, PY3, StringIO, binary_type, string_types, itervalues from six.moves import builtins from sphinx.util import force_decode +from sphinx.util import logging from sphinx.util.pycompat import NoneType if False: # For type annotation 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) @@ -339,7 +342,8 @@ class Signature(object): try: 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 = {} if bound_method: