Skip to content

Commit

Permalink
Fix sphinx-doc#5498: autodoc: unable to find type hints for a ``funct…
Browse files Browse the repository at this point in the history
…ools.partial``
  • Loading branch information
tk0miya committed Oct 14, 2018
1 parent 9158363 commit 5c8c611
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
--------
Expand Down
14 changes: 7 additions & 7 deletions sphinx/util/inspect.py
Expand Up @@ -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
Expand Down

0 comments on commit 5c8c611

Please sign in to comment.