Skip to content

Commit

Permalink
Merge pull request #5308 from tk0miya/5306_warning_for_invalid_typehints
Browse files Browse the repository at this point in the history
Fix #5306: autodoc: emit a warning for invalid typehints
  • Loading branch information
tk0miya committed Aug 18, 2018
2 parents 9cddc34 + 7975d73 commit fa8b84a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Features added
* #5246: Add :confval:`singlehtml_sidebars` to configure sidebars for singlehtml
builder
* #5273: doctest: Skip doctest conditionally
* #5306: autodoc: emit a warning for invalid typehints

Bugs fixed
----------
Expand Down
6 changes: 5 additions & 1 deletion sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
from six.moves import builtins

from sphinx.util import force_decode
from sphinx.util import logging
from sphinx.util.pycompat import NoneType

if False:
# For type annotation
from typing import Any, Callable, Dict, List, Tuple, Type # NOQA

logger = logging.getLogger(__name__)

memory_address_re = re.compile(r' at 0x[0-9a-f]{8,16}(?=>)', re.IGNORECASE)


Expand Down Expand Up @@ -339,7 +342,8 @@ def __init__(self, subject, bound_method=False, has_retval=True):

try:
self.annotations = typing.get_type_hints(subject) # type: ignore
except Exception:
except Exception as exc:
logger.warning('Invalid type annotation found on %r. Ingored: %r', subject, exc)
self.annotations = {}

if bound_method:
Expand Down

0 comments on commit fa8b84a

Please sign in to comment.