From a450eb7a7a48fd706c6cdbe6c35be63fd7ff13e6 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 17 Aug 2018 10:32:58 +0900 Subject: [PATCH] Fix #5306: autodoc: ``getargspec()`` raises NameError for invalid typehints --- CHANGES | 1 + sphinx/ext/autodoc/inspector.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index e1724747670..f3282e509a6 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/sphinx/ext/autodoc/inspector.py b/sphinx/ext/autodoc/inspector.py index 6e07c9547d1..be42237c656 100644 --- a/sphinx/ext/autodoc/inspector.py +++ b/sphinx/ext/autodoc/inspector.py @@ -130,8 +130,11 @@ def get_annotation(name): 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('(')