Skip to content

Commit f436852

Browse files
committed
Gracefully handle functions that don't have an annotations dict (#47)
1 parent d1d0a24 commit f436852

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

docs/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This release changes an internal API.
1414
Please delete the cache file before building documentation.
1515

1616
- Link import statements (:issue:`42`)
17+
- Gracefully handle functions that don't have an annotations dict (:issue:`47`)
1718
- Enable configurations without autodoc (:issue:`48`)
1819
- Support custom code block syntax (:issue:`49`)
1920
- Fix crash on annotation-only assignment (:issue:`50`)

src/sphinx_codeautolink/extension/resolve.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def locate_type(components: Tuple[str]) -> Optional[str]:
4141
# A possible function / method call needs to be last in the chain.
4242
# Otherwise we might follow return types on function attribute access.
4343
elif callable(value) and i == len(remaining) - 1:
44-
ret_annotation = value.__annotations__.get('return', None)
44+
annotations = getattr(value, '__annotations__', {})
45+
ret_annotation = annotations.get('return', None)
4546

4647
# Inner type from typing.Optional (Union[T, None])
4748
origin = getattr(ret_annotation, '__origin__', None)

0 commit comments

Comments
 (0)