Fix #5306: autodoc: `getargspec()` raises NameError for invalid typehints

This commit is contained in:
Takeshi KOMIYA 2018-08-17 10:32:58 +09:00
parent 2604920232
commit a450eb7a7a
2 changed files with 6 additions and 2 deletions

View File

@ -30,6 +30,7 @@ Bugs fixed
* autodoc: Optional types are wrongly rendered
* #5291: autodoc crashed by ForwardRef types
* #5211: autodoc: No docs generated for functools.partial functions
* #5306: autodoc: ``getargspec()`` raises NameError for invalid typehints
* #5298: imgmath: math_number_all causes equations to have two numbers in html
Testing

View File

@ -130,8 +130,11 @@ def formatargspec(function, args, varargs=None, varkw=None, defaults=None,
else:
return value
introspected_hints = (typing.get_type_hints(function) # type: ignore
if typing and hasattr(function, '__code__') else {})
try:
introspected_hints = (typing.get_type_hints(function) # type: ignore
if typing and hasattr(function, '__code__') else {})
except Exception:
introspected_hints = {}
fd = StringIO()
fd.write('(')