Fix #5498: autodoc: unable to find type hints for a `functools.partial`

This commit is contained in:
Takeshi KOMIYA 2018-10-14 14:28:38 +09:00
parent 9158363adc
commit b2cc425909
3 changed files with 8 additions and 2 deletions

View File

@ -21,6 +21,7 @@ Bugs fixed
* #3704: latex: wrong ``\label`` positioning for figures with a legend * #3704: latex: wrong ``\label`` positioning for figures with a legend
* #5496: C++, fix assertion when a symbol is declared more than twice. * #5496: C++, fix assertion when a symbol is declared more than twice.
* #5493: gettext: crashed with broken template * #5493: gettext: crashed with broken template
* #5498: autodoc: unable to find type hints for a ``functools.partial``
Testing Testing
-------- --------

View File

@ -358,10 +358,14 @@ class Signature(object):
self.argspec = getargspec(subject) self.argspec = getargspec(subject)
try: try:
self.annotations = typing.get_type_hints(subject) # type: ignore if ispartial(subject):
# get_type_hints() does not support partial objects
self.annotations = {} # type: Dict[str, Any]
else:
self.annotations = typing.get_type_hints(subject) # type: ignore
except Exception as exc: except Exception as exc:
if (3, 5, 0) <= sys.version_info < (3, 5, 3) and isinstance(exc, AttributeError): if (3, 5, 0) <= sys.version_info < (3, 5, 3) and isinstance(exc, AttributeError):
# python 3.5.2 raises ValueError for partial objects. # python 3.5.2 raises ValueError for classmethod-ized partial objects.
self.annotations = {} self.annotations = {}
else: else:
logger.warning('Invalid type annotation found on %r. Ignored: %r', logger.warning('Invalid type annotation found on %r. Ignored: %r',

View File

@ -112,6 +112,7 @@ def test_generate():
assert len(directive.result) == 0, directive.result assert len(directive.result) == 0, directive.result
assert warn_str in app._warning.getvalue() assert warn_str in app._warning.getvalue()
app._warning.truncate(0) app._warning.truncate(0)
app._warning.seek(0)
def assert_works(objtype, name, **kw): def assert_works(objtype, name, **kw):
inst = app.registry.documenters[objtype](directive, name) inst = app.registry.documenters[objtype](directive, name)