diff --git a/CHANGES b/CHANGES index b9365646dde..ba6ca9dd624 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Bugs fixed * #3704: latex: wrong ``\label`` positioning for figures with a legend * #5496: C++, fix assertion when a symbol is declared more than twice. * #5493: gettext: crashed with broken template +* #5498: autodoc: unable to find type hints for a ``functools.partial`` Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 48b8d953d5a..212292fc5ed 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -358,15 +358,15 @@ def __init__(self, subject, bound_method=False, has_retval=True): self.argspec = getargspec(subject) try: - self.annotations = typing.get_type_hints(subject) # type: ignore - except Exception as exc: - if (3, 5, 0) <= sys.version_info < (3, 5, 3) and isinstance(exc, AttributeError): - # python 3.5.2 raises ValueError for partial objects. + if ispartial(subject): + # get_type_hints() does not support partial objects self.annotations = {} else: - logger.warning('Invalid type annotation found on %r. Ignored: %r', - subject, exc) - self.annotations = {} + self.annotations = typing.get_type_hints(subject) # type: ignore + except Exception as exc: + logger.warning('Invalid type annotation found on %r. Ignored: %r', + subject, exc) + self.annotations = {} if bound_method: # client gives a hint that the subject is a bound method